home
/
code
/
hope.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
599f5f4
)
Add option type module.
author
Siraaj Khandkar
<siraaj@khandkar.net>
Sun, 10 Nov 2013 16:32:28 +0000
(11:32 -0500)
committer
Siraaj Khandkar
<siraaj@khandkar.net>
Sun, 10 Nov 2013 16:32:28 +0000
(11:32 -0500)
src/hope_option.erl
[new file with mode: 0644]
patch
|
blob
diff --git a/src/hope_option.erl
b/src/hope_option.erl
new file mode 100644
(file)
index 0000000..
ad0adac
--- /dev/null
+++ b/
src/hope_option.erl
@@ -0,0
+1,27
@@
+-module(hope_option).
+
+-export_type([ t/1
+ ]).
+
+-export([ put/2
+ , get/2
+ , map/2
+ ]).
+
+
+-type t(A) :: none | {some, A}.
+
+
+put(X, F) ->
+ case F(X)
+ of true -> {some, X}
+ ; false -> none
+ end.
+
+
+get({some, X}, _) -> X;
+get(none , Y) -> Y.
+
+
+map({some, X}, F) -> {some, F(X)};
+map(none , _) -> none.
This page took
0.039247 seconds
and
4
git commands to generate.