From: Siraaj Khandkar Date: Wed, 25 Mar 2015 14:15:21 +0000 (-0400) Subject: Define explicit map_ok as implementation of map X-Git-Tag: 2.4.1^0 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=fd4da0e0037ecf1f8b77b08d439fef0301e8a871;p=hope.git Define explicit map_ok as implementation of map in hope_result. --- diff --git a/src/hope.app.src b/src/hope.app.src index 78dd5bd..fee89b3 100644 --- a/src/hope.app.src +++ b/src/hope.app.src @@ -1,7 +1,7 @@ {application, hope, [ {description, "Higher Order Programming in Erlang"}, - {vsn, "2.4.0"}, + {vsn, "2.4.1"}, {registered, []}, {applications, [ kernel, diff --git a/src/hope_result.erl b/src/hope_result.erl index 930f2e0..0f9fb05 100644 --- a/src/hope_result.erl +++ b/src/hope_result.erl @@ -10,7 +10,8 @@ -export( [ return/1 - , map/2 + , map/2 % map/2 is alias for map_ok/2 + , map_ok/2 , map_error/2 , tag_error/2 , pipe/2 @@ -41,9 +42,14 @@ return(X) -> -spec map(t(A, Error), fun((A) -> (B))) -> t(B, Error). -map({ok, X}, F) -> +map({_, _}=T, F) -> + map_ok(T, F). + +-spec map_ok(t(A, Error), fun((A) -> (B))) -> + t(B, Error). +map_ok({ok, X}, F) -> {ok, F(X)}; -map({error, _}=Error, _) -> +map_ok({error, _}=Error, _) -> Error. -spec map_error(t(A, B), fun((B) -> (C))) -> @@ -109,7 +115,7 @@ lift_map_exn(F, MapOk, MapError) when is_function(F, 1) -> % Applying maps separately as to not unintentionally catch an exception % raised in a map. case Result - of {ok , _}=Ok -> map (Ok , MapOk) + of {ok , _}=Ok -> map_ok (Ok , MapOk) ; {error, _}=Error -> map_error(Error, MapError) end end.