Comparisons\isScalar()

predicate returns Closure returns bool pure
string → (mixed → bool)
At a glance — Curried type-check. Bind a PHP gettype() name; the returned Closure answers "is this of that type?".

Creates a predicate Closure that is true when the passed value's type matches the bound type-name string.

/**
  * @param string $source Type name (bool, boolean, integer, object, ...).
  * @return Closure(mixed):bool
  */
Comparisons\isScalar(string $source): Closure

Returned Closure

When Comparisons\isScalar() 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.

$isString = Comparisons\isScalar('string');
var_dump($isString('hello')); // true
var_dump($isString(42));      // false

$isInt = Comparisons\isScalar('integer');
array_filter([1, '2', 3, 4.5, 5], $isInt); // [1, 3, 5]

Details

Comparisons Functions

Releated Type check Functions