, iter/2
, pipe/2
, of_result/1
+ , of_undefined/1
]).
t(A).
of_result({ok, X}) -> {some, X};
of_result({error, _}) -> none.
+
+-spec of_undefined(undefined | A) ->
+ t(A).
+of_undefined(undefined) -> none;
+of_undefined(X) -> {some, X}.
%% Test cases
-export(
[ t_of_result/1
+ , t_of_undefined/1
, t_put/1
, t_get/1
, t_map/1
groups() ->
Tests =
[ t_of_result
+ , t_of_undefined
, t_put
, t_get
, t_map
none = hope_option:pipe(Steps, 1),
none = hope_option:pipe(Steps, 2),
none = hope_option:pipe(Steps, 3).
+
+t_of_undefined(_Cfg) ->
+ Foo = foo,
+ Bar = bar,
+ Baz = baz,
+ {some, Foo} = hope_option:of_undefined(Foo),
+ {some, Bar} = hope_option:of_undefined(Bar),
+ {some, Baz} = hope_option:of_undefined(Baz),
+ none = hope_option:of_undefined(undefined).