Define and implement a generic monad behavior.
[hope.git] / src / hope_result.erl
index feda537..1114197 100644 (file)
@@ -1,12 +1,15 @@
 -module(hope_result).
 
+-behavior(hope_monad).
 
 -export_type(
     [ t/2
     ]).
 
 -export(
-    [ pipe/2
+    [ return/1
+    , map/2
+    , pipe/2
     , lift_exn/1
     , lift_exn/2
     ]).
     .
 
 
+-spec return(A) ->
+    {ok, A}.
+return(X) ->
+    {ok, X}.
+
+-spec map(t(A, Error), fun((A) -> (B))) ->
+    t(B, Error).
+map({ok, X}, F) ->
+    {ok, F(X)};
+map({error, _}=Error, _) ->
+    Error.
+
 -spec pipe([F], X) ->
     t(Ok, Error)
     when X     :: any()
This page took 0.02028 seconds and 4 git commands to generate.