home
/
code
/
hope.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bring-back manual test case for hope_list
[hope.git]
/
src
/
hope_option.erl
diff --git
a/src/hope_option.erl
b/src/hope_option.erl
index
7a87438
..
996e342
100644
(file)
--- a/
src/hope_option.erl
+++ b/
src/hope_option.erl
@@
-7,15
+7,19
@@
]).
-export(
]).
-export(
- [ put/2
- , get/2
- , return/1
- , return/2
+ % Generic monad interface
+ [ return/1
, map/2
, map/2
- , iter/2
, pipe/2
, pipe/2
+
+ % Specific to hope_option:t()
+ , return/2
+ , put/2
+ , get/2
+ , iter/2
, of_result/1
, of_undefined/1
, of_result/1
, of_undefined/1
+ , validate/2
]).
]).
@@
-77,3
+81,13
@@
of_result({error, _}) -> none.
t(A).
of_undefined(undefined) -> none;
of_undefined(X) -> {some, X}.
t(A).
of_undefined(undefined) -> none;
of_undefined(X) -> {some, X}.
+
+-spec validate(t(A), fun((A) -> boolean())) ->
+ t(A).
+validate(none, _) ->
+ none;
+validate({some, X}=T, F) ->
+ case F(X)
+ of false -> none
+ ; true -> T
+ end.
This page took
0.027411 seconds
and
4
git commands to generate.