-export(
[ pipe/2
, lift_exn/1
+ , lift_exn/2
]).
{error, {Class, Reason}}
end
end.
+
+-spec lift_exn(F, Label) -> G
+ when F :: fun((A)-> B)
+ , G :: fun((A)-> t(B, {Label, {Class, Reason :: any()}}))
+ , Class :: error
+ | exit
+ | throw
+ .
+lift_exn(F, Label) when is_function(F, 1) ->
+ fun(X) ->
+ try
+ {ok, F(X)}
+ catch Class:Reason ->
+ {error, {Label, {Class, Reason}}}
+ end
+ end.
t_lift_exn(_Cfg) ->
Class = throw,
Reason = foofoo,
+ Label = bar,
F = fun (ok) -> apply(erlang, Class, [Reason]) end,
G = hope_result:lift_exn(F),
- {error, {Class, Reason}} = G(ok).
+ H = hope_result:lift_exn(F, Label),
+ {error, {Class, Reason}} = G(ok),
+ {error, {Label, {Class, Reason}}} = H(ok).