Current section
Files
Jump to
Current section
Files
src/ask@predicate.erl
-module(ask@predicate).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([always/0, never/0, 'and'/2, 'or'/2, 'not'/1, every/1, some/1, all/1, any/1, map_input/2]).
-spec always() -> fun((any()) -> boolean()).
always() ->
fun(_) -> true end.
-spec never() -> fun((any()) -> boolean()).
never() ->
fun(_) -> false end.
-spec 'and'(fun((FNK) -> boolean()), fun((FNK) -> boolean())) -> fun((FNK) -> boolean()).
'and'(First, Second) ->
fun(Value) -> First(Value) andalso Second(Value) end.
-spec 'or'(fun((FNO) -> boolean()), fun((FNO) -> boolean())) -> fun((FNO) -> boolean()).
'or'(First, Second) ->
fun(Value) -> First(Value) orelse Second(Value) end.
-spec 'not'(fun((FNS) -> boolean())) -> fun((FNS) -> boolean()).
'not'(P) ->
fun(Value) -> not P(Value) end.
-spec do_every(list(fun((FNV) -> boolean())), FNV, boolean()) -> boolean().
do_every(Ps, Value, Acc) ->
case Ps of
[] ->
Acc;
[P | Ps@1] ->
do_every(Ps@1, Value, Acc andalso P(Value))
end.
-spec every(list(fun((FNY) -> boolean()))) -> fun((FNY) -> boolean()).
every(Ps) ->
fun(Value) -> do_every(Ps, Value, true) end.
-spec do_some(list(fun((FOC) -> boolean())), FOC, boolean()) -> boolean().
do_some(Ps, Value, Acc) ->
case Ps of
[] ->
Acc;
[P | Ps@1] ->
do_some(Ps@1, Value, Acc orelse P(Value))
end.
-spec some(list(fun((FOF) -> boolean()))) -> fun((FOF) -> boolean()).
some(Ps) ->
fun(Value) -> do_some(Ps, Value, false) end.
-spec all(fun((FOJ) -> boolean())) -> fun((list(FOJ)) -> boolean()).
all(P) ->
fun(A) -> _pipe = A,
gleam@list:all(_pipe, P) end.
-spec any(fun((FON) -> boolean())) -> fun((list(FON)) -> boolean()).
any(P) ->
fun(A) -> _pipe = A,
gleam@list:any(_pipe, P) end.
-spec map_input(fun((FOR) -> boolean()), fun((FOT) -> FOR)) -> fun((FOT) -> boolean()).
map_input(P, Fun) ->
fun(B) -> P(Fun(B)) end.