Option::foldLeft( mixed $initialValue, callable $callable )
Binary operator for the initial value and the option’s value.
Description
If empty, the initial value is returned. If non-empty, the callable receives the initial value and the option’s value as arguments
$some = new Some(5); $none = None::create(); $result = $some->foldLeft(1, function($a, $b) { return $a + $b; }); // int(6) $result = $none->foldLeft(1, function($a, $b) { return $a + $b; }); // int(1)
// This can be used instead of something like the following: $option = Option::fromValue($integerOrNull); $result = 1; if ( ! $option->isEmpty()) { $result += $option->get(); }
Parameters
- $initialValue
-
(Required)
- $callable
-
(Required) function(initialValue, callable): result
Return
(mixed)
Source
File: vendor/phpoption/phpoption/src/PhpOption/Option.php
abstract public function foldLeft($initialValue, $callable);