Skip to content

not

not<A>(predicate): (…args) => boolean

Defined in: Composition/not.ts:27

Negates a predicate function. Returns a new predicate that returns true when the original returns false, and vice versa.

A extends readonly unknown[]

(…args) => boolean

(…args) => boolean

const isEven = (n: number) => n % 2 === 0;
const isOdd = not(isEven);

isOdd(3); // true
isOdd(4); // false

// With array methods
const numbers = [1, 2, 3, 4, 5];
numbers.filter(not(isEven)); // [1, 3, 5]

// In pipelines
const users = [{ name: "Alice", isAdmin: false }, { name: "Bob", isAdmin: true }];
const isAdmin = (u: { name: string; isAdmin: boolean }) => u.isAdmin;
pipe(
  users,
  Arr.filter(not(isAdmin)),
  Arr.map((u: { name: string; isAdmin: boolean }) => u.name)
);