Add labeled result lifting.
[hope.git] / src / hope_result.erl
index 44f3ddd..feda537 100644 (file)
@@ -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.
This page took 0.024652 seconds and 4 git commands to generate.