home
/
code
/
hope.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add hope_option:of_result/1
[hope.git]
/
src
/
hope_option.erl
diff --git
a/src/hope_option.erl
b/src/hope_option.erl
index
622c06d
..
ab6eab7
100644
(file)
--- a/
src/hope_option.erl
+++ b/
src/hope_option.erl
@@
-9,6
+9,8
@@
[ put/2
, get/2
, map/2
[ put/2
, get/2
, map/2
+ , iter/2
+ , of_result/1
]).
]).
@@
-18,14
+20,30
@@
.
.
+-spec put(A, fun((A) -> boolean())) ->
+ t(A).
put(X, F) ->
case F(X)
of true -> {some, X}
; false -> none
end.
put(X, F) ->
case F(X)
of true -> {some, X}
; false -> none
end.
+-spec get(t(A), Default :: A) ->
+ A.
get({some, X}, _) -> X;
get(none , Y) -> Y.
get({some, X}, _) -> X;
get(none , Y) -> Y.
+-spec map(t(A), fun((A) -> (B))) ->
+ t(B).
map({some, X}, F) -> {some, F(X)};
map(none , _) -> none.
map({some, X}, F) -> {some, F(X)};
map(none , _) -> none.
+
+-spec iter(t(A), fun((A) -> (ok))) ->
+ ok.
+iter({some, X}, F) -> ok = F(X);
+iter(none , _) -> ok.
+
+-spec of_result(hope_result:t(A, _B)) ->
+ t(A).
+of_result({ok, X}) -> {some, X};
+of_result({error, _}) -> none.
This page took
0.037562 seconds
and
4
git commands to generate.