From: Siraaj Khandkar Date: Tue, 15 Jul 2014 00:48:04 +0000 (-0400) Subject: Add specs. X-Git-Tag: 1.0.0~31 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=ed9905af6fa1dba6f89759d6dbfc970426122bde;p=hope.git Add specs. --- diff --git a/src/hope_option.erl b/src/hope_option.erl index 622c06d..c461d04 100644 --- a/src/hope_option.erl +++ b/src/hope_option.erl @@ -18,14 +18,20 @@ . +-spec put(A, fun((A) -> boolean())) -> + t(A). put(X, F) -> case F(X) of true -> {some, X} ; false -> none end. +-spec get(t(A), Default :: A) -> + A. get({some, X}, _) -> X; get(none , Y) -> Y. +-spec map(t(A), fun((A) -> (B))) -> + t(B). map({some, X}, F) -> {some, F(X)}; map(none , _) -> none. diff --git a/src/hope_result.erl b/src/hope_result.erl index a40629a..5d0ea7e 100644 --- a/src/hope_result.erl +++ b/src/hope_result.erl @@ -16,6 +16,13 @@ . +-spec pipe([F], X) -> + t(Ok, Error) + when X :: any() + , Ok :: any() + , Error :: any() + , F :: fun((X) -> t(Ok, Error)) + . pipe([] , X) -> X; pipe([F|Fs], X) -> case F(X)