Skip to content

using

using<A, B>(f): (p) => Predicate<B>

Defined in: Core/Predicate.ts:106

Adapts a Predicate<A> to work on a different input type B by applying f to extract the relevant A from a B before running the check.

Data-last — the predicate is the data being piped; f is the extractor.

A

B

(b) => A

(p): Predicate<B>

Predicate<A>

Predicate<B>

type User = { name: string; age: number };

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

// Lift isAdult to work on Users by extracting the age field
const isAdultUser: Predicate<User> = pipe(
  isAdult,
  Predicate.using((u: User) => u.age)
);

isAdultUser({ name: "Alice", age: 30 });  // true
isAdultUser({ name: "Bob",   age: 15 });  // false