-module(ask@predicate). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([always/0, never/0, 'and'/2, 'or'/2, negate/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((FPQ) -> boolean()), fun((FPQ) -> boolean())) -> fun((FPQ) -> boolean()). 'and'(First, Second) -> fun(Value) -> First(Value) andalso Second(Value) end. -spec 'or'(fun((FPU) -> boolean()), fun((FPU) -> boolean())) -> fun((FPU) -> boolean()). 'or'(First, Second) -> fun(Value) -> First(Value) orelse Second(Value) end. -spec negate(fun((FPY) -> boolean())) -> fun((FPY) -> boolean()). negate(P) -> fun(Value) -> not P(Value) end. -spec do_every(list(fun((FQB) -> boolean())), FQB, 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((FQE) -> boolean()))) -> fun((FQE) -> boolean()). every(Ps) -> fun(Value) -> do_every(Ps, Value, true) end. -spec do_some(list(fun((FQI) -> boolean())), FQI, 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((FQL) -> boolean()))) -> fun((FQL) -> boolean()). some(Ps) -> fun(Value) -> do_some(Ps, Value, false) end. -spec all(fun((FQP) -> boolean())) -> fun((list(FQP)) -> boolean()). all(P) -> fun(A) -> gleam@list:all(A, P) end. -spec any(fun((FQT) -> boolean())) -> fun((list(FQT)) -> boolean()). any(P) -> fun(A) -> gleam@list:any(A, P) end. -spec map_input(fun((FQX) -> boolean()), fun((FQZ) -> FQX)) -> fun((FQZ) -> boolean()). map_input(P, Fun) -> fun(B) -> P(Fun(B)) end.