Add hope_option:return/2, which accepts a condition 2.3.0
authorSiraaj Khandkar <siraaj@khandkar.net>
Mon, 16 Feb 2015 07:44:35 +0000 (02:44 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Mon, 16 Feb 2015 07:44:35 +0000 (02:44 -0500)
src/hope.app.src
src/hope_option.erl

index f5048f9..8c4d425 100644 (file)
@@ -1,7 +1,7 @@
 {application, hope,
  [
   {description, "Higher Order Programming in Erlang"},
-  {vsn, "2.2.0"},
+  {vsn, "2.3.0"},
   {registered, []},
   {applications, [
                   kernel,
index 5721628..7a87438 100644 (file)
@@ -10,6 +10,7 @@
     [ put/2
     , get/2
     , return/1
+    , return/2
     , map/2
     , iter/2
     , pipe/2
 -spec put(A, fun((A) -> boolean())) ->
     t(A).
 put(X, F) ->
-    case F(X)
-    of  true  -> {some, X}
-    ;   false -> none
-    end.
+    return(X, F).
 
 -spec get(t(A), Default :: A) ->
     A.
@@ -42,6 +40,14 @@ get(none     , Y) -> Y.
 return(X) ->
     {some, X}.
 
+-spec return(A, fun((A) -> boolean())) ->
+    t(A).
+return(X, Condition) ->
+    case Condition(X)
+    of  true  -> {some, X}
+    ;   false -> none
+    end.
+
 -spec map(t(A), fun((A) -> (B))) ->
     t(B).
 map({some, X}, F) -> {some, F(X)};
This page took 0.024921 seconds and 4 git commands to generate.