Function complement

Returns the complement of a function.

  • If the result of the function is truthy, the result of the complement is falsy.
  • If the result of the function is falsy, the result of the complement is truthy.
const a = (x: number) => x > 0;
const b = complement(a);
console.log(a(1)); // true
console.log(b(1)); // false
  • Type Parameters

    • Fn extends AnyFn

      The type of the function.

    Parameters

    • fn: Fn

      The function.

    Returns ((...args: Parameters<Fn>) => boolean)

    A function whose result is the negation of the result of fn.

      • (...args): boolean
      • Parameters

        • Rest...args: Parameters<Fn>

        Returns boolean