, iter/2
, of_result/1
, of_undefined/1
+ , validate/2
]).
t(A).
of_undefined(undefined) -> none;
of_undefined(X) -> {some, X}.
+
+-spec validate(t(A), fun((A) -> boolean())) ->
+ t(A).
+validate(none, _) ->
+ none;
+validate({some, X}=T, F) ->
+ case F(X)
+ of false -> none
+ ; true -> T
+ end.
, t_map/1
, t_iter/1
, t_pipe/1
+ , t_validate/1
]).
, t_map
, t_iter
, t_pipe
+ , t_validate
],
Properties = [parallel],
[ {?GROUP, Properties, Tests}
{some, Bar} = hope_option:of_undefined(Bar),
{some, Baz} = hope_option:of_undefined(Baz),
none = hope_option:of_undefined(undefined).
+
+t_validate(_Cfg) ->
+ IsFoo = fun (X) -> X =:= foo end,
+ none = hope_option:validate(none, IsFoo),
+ none = hope_option:validate({some, bar}, IsFoo),
+ {some, foo} = hope_option:validate({some, foo}, IsFoo).