Skip to content

not

Creates a function that returns the boolean-inverted value of the provided function's result.

Syntax

typescript
not<T extends (...args: any[]) => boolean>(callback: T): (...args: Parameters<T>) => boolean

Parameters

NameTypeDescription
callbackTFunction whose result will be inverted.

Returns

TypeDescription
(...args: Parameters<T>) => booleanFunction that returns the boolean-inverted value.

Example

typescript
const isEven = (x: number) => x % 2 === 0;
const isOdd = not(isEven);
isOdd(3); // true
isOdd(4); // false

Notes

  • Throws a TypeError if the argument is not a function.
  • Useful for creating inverse predicates in a functional way.

References

Released under the MIT License.