X-Git-Url: https://git.xandkar.net/?p=hope.git;a=blobdiff_plain;f=src%2Fhope_result.erl;h=1114197beca3e60d7ac8e5d8f7b2744e25b46b3c;hp=feda5379c1e6ec36e506530547937928b79e82a9;hb=4af0774b16181c76d0deedf0911d53409c8f1078;hpb=2dc71691ff8d7494f80a2af26994c186779d6898 diff --git a/src/hope_result.erl b/src/hope_result.erl index feda537..1114197 100644 --- a/src/hope_result.erl +++ b/src/hope_result.erl @@ -1,12 +1,15 @@ -module(hope_result). +-behavior(hope_monad). -export_type( [ t/2 ]). -export( - [ pipe/2 + [ return/1 + , map/2 + , pipe/2 , lift_exn/1 , lift_exn/2 ]). @@ -18,6 +21,18 @@ . +-spec return(A) -> + {ok, A}. +return(X) -> + {ok, X}. + +-spec map(t(A, Error), fun((A) -> (B))) -> + t(B, Error). +map({ok, X}, F) -> + {ok, F(X)}; +map({error, _}=Error, _) -> + Error. + -spec pipe([F], X) -> t(Ok, Error) when X :: any()