Predicate
Predicate:
object
Defined in: Core/Predicate.ts:29
Type Declaration
Section titled “Type Declaration”all: <
A>(predicates) =>Predicate<A>
Combines an array of predicates with AND: passes only when every predicate holds.
Returns true for an empty array (vacuous truth).
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicates
Section titled “predicates”readonly Predicate<A>[]
Returns
Section titled “Returns”Predicate<A>
Example
Section titled “Example”and: <
A>(that) => (predicate) =>Predicate<A>
Combines two predicates with logical AND: passes only when both hold.
Data-last — the first predicate is the data being piped.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Predicate<A>
Returns
Section titled “Returns”(predicate) => Predicate<A>
Example
Section titled “Example”any: <
A>(predicates) =>Predicate<A>
Combines an array of predicates with OR: passes when at least one holds.
Returns false for an empty array.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicates
Section titled “predicates”readonly Predicate<A>[]
Returns
Section titled “Returns”Predicate<A>
Example
Section titled “Example”from:
object
from.Refinement
Section titled “from.Refinement”Refinement: <
A,B>(refinement) =>Predicate<A> =fromRefinement
Converts a Refinement<A, B> into a Predicate<A>, discarding the compile-time
narrowing. Use this when you want to combine a type guard with plain predicates
using and, or, or all.
This is a zero-cost runtime type cast.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”refinement
Section titled “refinement”Refinement<A, B>
Returns
Section titled “Returns”Predicate<A>
Refinement.to.Predicate for the inverse converter under the Refinement namespace.
Example
Section titled “Example”match: <
A,B,C>(branches,fallback) => (value) =>B|C
Performs declarative conditional branching over [predicate, handler] pairs,
returning the handler result of the first matching predicate or evaluating the fallback.
Type Parameters
Section titled “Type Parameters”A
B
C = B
Parameters
Section titled “Parameters”branches
Section titled “branches”readonly (readonly [Predicate<A>, (value) => B])[]
fallback
Section titled “fallback”(value) => C
Returns
Section titled “Returns”(value) => B | C
Example
Section titled “Example”not: <
A>(predicate) =>Predicate<A>
Negates a predicate: the result passes exactly when the original fails.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”Predicate<A>
Returns
Section titled “Returns”Predicate<A>
Example
Section titled “Example”or: <
A>(that) => (predicate) =>Predicate<A>
Combines two predicates with logical OR: passes when either holds.
Data-last — the first predicate is the data being piped.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Predicate<A>
Returns
Section titled “Returns”(predicate) => Predicate<A>
Example
Section titled “Example”using: <
A,B>(transform) => (predicate) =>Predicate<B>
Adapts a Predicate<A> to work on a different input type B by applying transform
to extract the relevant A from a B before running the check.
Data-last — the predicate is the data being piped; transform is the extractor.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => A
Returns
Section titled “Returns”(predicate) => Predicate<B>