Add option type module.
authorSiraaj Khandkar <siraaj@khandkar.net>
Sun, 10 Nov 2013 16:32:28 +0000 (11:32 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Sun, 10 Nov 2013 16:32:28 +0000 (11:32 -0500)
src/hope_option.erl [new file with mode: 0644]

diff --git a/src/hope_option.erl b/src/hope_option.erl
new file mode 100644 (file)
index 0000000..ad0adac
--- /dev/null
@@ -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.