Packages

Functional utilities for building custom predicates, orderings, and equivalences

Current section

Files

Jump to
ask src ask@predicate.erl
Raw

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((FNC) -> boolean()), fun((FNC) -> boolean())) -> fun((FNC) -> boolean()).
'and'(First, Second) ->
fun(Value) -> First(Value) andalso Second(Value) end.
-spec 'or'(fun((FNG) -> boolean()), fun((FNG) -> boolean())) -> fun((FNG) -> boolean()).
'or'(First, Second) ->
fun(Value) -> First(Value) orelse Second(Value) end.
-spec 'not'(fun((FNK) -> boolean())) -> fun((FNK) -> boolean()).
'not'(P) ->
fun(Value) -> not P(Value) end.
-spec every(list(fun((FNN) -> boolean()))) -> fun((FNN) -> boolean()).
every(Ps) ->
case Ps of
[] ->
fun(_) -> true end;
[P | Ps@1] ->
fun(Value) -> P(Value) andalso (every(Ps@1))(Value) end
end.
-spec some(list(fun((FNR) -> boolean()))) -> fun((FNR) -> boolean()).
some(Ps) ->
case Ps of
[] ->
fun(_) -> false end;
[P | Ps@1] ->
fun(Value) -> P(Value) orelse (some(Ps@1))(Value) end
end.
-spec all(fun((FNV) -> boolean())) -> fun((list(FNV)) -> boolean()).
all(P) ->
fun(A) -> _pipe = A,
gleam@list:all(_pipe, P) end.
-spec any(fun((FNZ) -> boolean())) -> fun((list(FNZ)) -> boolean()).
any(P) ->
fun(A) -> _pipe = A,
gleam@list:any(_pipe, P) end.
-spec map_input(fun((FOD) -> boolean()), fun((FOF) -> FOD)) -> fun((FOF) -> boolean()).
map_input(P, Fun) ->
fun(B) -> P(Fun(B)) end.