X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=src%2Fhope_option.erl;h=c461d04d1b70d3bbd292e954aa21c55eb4921c5e;hb=ed9905af6fa1dba6f89759d6dbfc970426122bde;hp=92636c9f7191689526783806cbf85c0e9a7599fb;hpb=3b156801097bcd07272f1db3a62a675495fa9d77;p=hope.git diff --git a/src/hope_option.erl b/src/hope_option.erl index 92636c9..c461d04 100644 --- a/src/hope_option.erl +++ b/src/hope_option.erl @@ -1,5 +1,6 @@ -module(hope_option). + -export_type( [ t/1 ]). @@ -17,16 +18,20 @@ . +-spec put(A, fun((A) -> boolean())) -> + t(A). 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. - +-spec map(t(A), fun((A) -> (B))) -> + t(B). map({some, X}, F) -> {some, F(X)}; map(none , _) -> none.