es-toolkit/docs/reference/function/negate.md
2024-07-15 19:11:43 +09:00

501 B

negate

Creates a function that negates the result of the predicate function.

Signature

function negate<F extends (...args: unknown[]) => boolean>(func: F): F;

Parameters

  • func (F extends (args: ...Parameters) => unknown): The function to negate.

Returns

  • (F): Returns the new negated function.

Examples

import { negate } from 'es-toolkit/function';

negate(() => true)(); // returns 'false'
negate(() => false)(); // returns 'true'