home
/
code
/
hope.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Define explicit map_ok as implementation of map
[hope.git]
/
src
/
hope_result.erl
diff --git
a/src/hope_result.erl
b/src/hope_result.erl
index
930f2e0
..
0f9fb05
100644
(file)
--- a/
src/hope_result.erl
+++ b/
src/hope_result.erl
@@
-10,7
+10,8
@@
-export(
[ return/1
-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
, 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).
-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)};
{ok, F(X)};
-map({error, _}=Error, _) ->
+map
_ok
({error, _}=Error, _) ->
Error.
-spec map_error(t(A, B), fun((B) -> (C))) ->
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
% 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.
; {error, _}=Error -> map_error(Error, MapError)
end
end.
This page took
0.025169 seconds
and
4
git commands to generate.