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>) => booleanParameters
| Name | Type | Description |
|---|---|---|
callback | T | Function whose result will be inverted. |
Returns
| Type | Description |
|---|---|
(...args: Parameters<T>) => boolean | Function that returns the boolean-inverted value. |
Example
typescript
const isEven = (x: number) => x % 2 === 0;
const isOdd = not(isEven);
isOdd(3); // true
isOdd(4); // falseNotes
- Throws a
TypeErrorif the argument is not a function. - Useful for creating inverse predicates in a functional way.
