Comparisons\not()

higher-order predicate returns Closure returns bool pure
(T → bool) → (T → bool)
At a glance — Flip a predicate without writing a new one. Especially handy for turning library predicates into "not-x" filters.

Negates a predicate. Takes a callable returning bool and returns a Closure that returns the opposite bool for any input.

/**
  * @param callable(mixed):bool $callable
  * @return Closure(mixed):bool
  */
Comparisons\not(callable $callable): Closure

Returned Closure

When Comparisons\not() is called, it returns the following Closure which can be used like a regular function.

/**
  * @param mixed $value
  * @return bool
  */
$function ($value): bool

Examples

Partial Application

This can be used to create a simple closure which can be used as a regular function.

$isNotEmpty = Comparisons\not('empty');
$isNotString = Comparisons\not('is_string');
$isNotZero = Comparisons\not(Comparisons\isEqualTo(0));

var_dump($isNotZero(0)); // false
var_dump($isNotZero(1)); // true

$nonStrings = array_filter([1, 'a', 2, 'b'], $isNotString);
print_r($nonStrings); // [1, 2]

Details

Comparisons Functions

Releated Combinators Functions