Comparisons\isEqualTo()

predicate returns Closure returns bool pure
T → (mixed → bool)
At a glance — Bind a value once; the returned Closure compares with ==. Use isScalar or type predicates if you need strict equality plus type-matching.

Creates a predicate Closure that is true when the passed value is loosely equal (==) to the bound value.

/**
  * @param mixed $a
  * @return Closure(mixed):bool
  */
Comparisons\isEqualTo($a): Closure

Returned Closure

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

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

Examples

Partial Application

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

$isFoo = Comparisons\isEqualTo('foo');

var_dump($isFoo('foo'));  // true
var_dump($isFoo('bar'));  // false

$foos = array_filter(['foo', 'bar', 'foo', 'baz'], $isFoo);
count($foos); // 2

Curried

This can be called inline using currying.

var_dump(Comparisons\isEqualTo(1)('1')); // true (loose ==)

Details

Comparisons Functions

Releated Equality Functions