3 -behavior(hope_gen_monad).
10 % Generic monad interface
15 % Specific to hope_option:t()
31 -spec put(A, fun((A) -> boolean())) ->
36 -spec get(t(A), Default :: A) ->
38 get({some, X}, _) -> X;
46 -spec return(A, fun((A) -> boolean())) ->
48 return(X, Condition) ->
54 -spec map(t(A), fun((A) -> (B))) ->
56 map({some, X}, F) -> {some, F(X)};
57 map(none , _) -> none.
59 -spec iter(t(A), fun((A) -> (ok))) ->
61 iter({some, X}, F) -> ok = F(X);
64 -spec pipe([fun((A) -> t(B))], A) ->
71 ; {some, Y} -> pipe(Fs, Y)
74 -spec of_result(hope_result:t(A, _B)) ->
76 of_result({ok, X}) -> {some, X};
77 of_result({error, _}) -> none.
79 -spec of_undefined(undefined | A) ->
81 of_undefined(undefined) -> none;
82 of_undefined(X) -> {some, X}.