X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=src%2Fhope_result.erl;h=feda5379c1e6ec36e506530547937928b79e82a9;hb=refs%2Ftags%2F1.1.0;hp=44f3ddd58b92e21ba0941e4d274b31d495fd68c9;hpb=371e63336e774865c4746b0a9a849eb44f10f98a;p=hope.git diff --git a/src/hope_result.erl b/src/hope_result.erl index 44f3ddd..feda537 100644 --- a/src/hope_result.erl +++ b/src/hope_result.erl @@ -8,6 +8,7 @@ -export( [ pipe/2 , lift_exn/1 + , lift_exn/2 ]). @@ -47,3 +48,19 @@ lift_exn(F) when is_function(F, 1) -> {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.