From: Siraaj Khandkar Date: Sun, 10 Nov 2013 16:32:28 +0000 (-0500) Subject: Add option type module. X-Git-Tag: 1.0.0~37 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=e492ea132d3b73d2597fc8b832128dc40fed63ba;p=hope.git Add option type module. --- diff --git a/src/hope_option.erl b/src/hope_option.erl new file mode 100644 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.