home
/
code
/
hope.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Define and implement a generic monad behavior.
[hope.git]
/
src
/
hope_result.erl
diff --git
a/src/hope_result.erl
b/src/hope_result.erl
index
feda537
..
1114197
100644
(file)
--- a/
src/hope_result.erl
+++ b/
src/hope_result.erl
@@
-1,12
+1,15
@@
-module(hope_result).
-module(hope_result).
+-behavior(hope_monad).
-export_type(
[ t/2
]).
-export(
-export_type(
[ t/2
]).
-export(
- [ pipe/2
+ [ return/1
+ , map/2
+ , pipe/2
, lift_exn/1
, lift_exn/2
]).
, lift_exn/1
, lift_exn/2
]).
@@
-18,6
+21,18
@@
.
.
+-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()
-spec pipe([F], X) ->
t(Ok, Error)
when X :: any()
This page took
0.027321 seconds
and
4
git commands to generate.