Skip to content

webshrine / stdlib/src / negate

Function: negate()

negate<T>(fn): T

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

  • Supports async predicates.

Type Parameters

T extends (...parameters) => boolean | (...parameters) => Promise<boolean>

Parameters

fn

T

Returns

T

Example

ts
function isEven(n) {
  return n % 2 == 0;
}
const isOdd = _.negate(isEven);

_.filter([1, 2, 3, 4, 5, 6], isOdd);
// => [1, 3, 5]

Defined in

packages/stdlib/src/wrappers/index.ts:45