From 9a5e47faa30b6f3fbd9b0521b238c2d1076de498 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Mon, 16 Feb 2015 02:44:35 -0500 Subject: [PATCH] Add hope_option:return/2, which accepts a condition --- src/hope.app.src | 2 +- src/hope_option.erl | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/hope.app.src b/src/hope.app.src index f5048f9..8c4d425 100644 --- a/src/hope.app.src +++ b/src/hope.app.src @@ -1,7 +1,7 @@ {application, hope, [ {description, "Higher Order Programming in Erlang"}, - {vsn, "2.2.0"}, + {vsn, "2.3.0"}, {registered, []}, {applications, [ kernel, diff --git a/src/hope_option.erl b/src/hope_option.erl index 5721628..7a87438 100644 --- a/src/hope_option.erl +++ b/src/hope_option.erl @@ -10,6 +10,7 @@ [ put/2 , get/2 , return/1 + , return/2 , map/2 , iter/2 , pipe/2 @@ -27,10 +28,7 @@ -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)}; -- 2.20.1