Skip to content

Predicate

Predicate<A> = (a) => boolean

Defined in: Core/Predicate.ts:29

A boolean-valued function over a type A.

A Predicate<A> is the simpler sibling of Refinement<A, B>: it tests whether a value satisfies a condition at runtime but carries no compile-time narrowing guarantee. Use it when you need to combine, negate, or adapt boolean checks as first-class values and do not require the extra type information that a Refinement provides.

Every Refinement<A, B> is a Predicate<A> — convert with Predicate.fromRefinement when you want to compose a narrowing check alongside plain predicates.

A

A

boolean

const isAdult: Predicate<number> = n => n >= 18;
const isRetired: Predicate<number> = n => n >= 65;

const isWorkingAge: Predicate<number> = pipe(
  isAdult,
  Predicate.and(Predicate.not(isRetired))
);

isWorkingAge(30);  // true
isWorkingAge(15);  // false
isWorkingAge(70);  // false