Add specs.
[hope.git] / src / hope_option.erl
... / ...
CommitLineData
1-module(hope_option).
2
3
4-export_type(
5 [ t/1
6 ]).
7
8-export(
9 [ put/2
10 , get/2
11 , map/2
12 ]).
13
14
15-type t(A) ::
16 none
17 | {some, A}
18 .
19
20
21-spec put(A, fun((A) -> boolean())) ->
22 t(A).
23put(X, F) ->
24 case F(X)
25 of true -> {some, X}
26 ; false -> none
27 end.
28
29-spec get(t(A), Default :: A) ->
30 A.
31get({some, X}, _) -> X;
32get(none , Y) -> Y.
33
34-spec map(t(A), fun((A) -> (B))) ->
35 t(B).
36map({some, X}, F) -> {some, F(X)};
37map(none , _) -> none.
This page took 0.024174 seconds and 4 git commands to generate.