Add labeled result lifting. 1.1.0
authorSiraaj Khandkar <siraaj@khandkar.net>
Thu, 11 Dec 2014 21:04:17 +0000 (16:04 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Thu, 11 Dec 2014 21:04:17 +0000 (16:04 -0500)
src/hope.app.src
src/hope_result.erl
test/hope_result_SUITE.erl

index bf3fd3d..3b019ef 100644 (file)
@@ -1,7 +1,7 @@
 {application, hope,
  [
   {description, "Higher Order Programming in Erlang"},
-  {vsn, "0.0.0"},
+  {vsn, "1.1.0"},
   {registered, []},
   {applications, [
                   kernel,
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.
index 9587345..390f28c 100644 (file)
@@ -90,6 +90,9 @@ t_hope_result_specs(_) ->
 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).
This page took 0.028349 seconds and 4 git commands to generate.