- alias:
Any::chain
Iterate over a list of elements, yielding each in turn to an $callable function
{mixed} $value
- manipulation target
{Set}::chain($target): Chain
<?php
use Dsheiko\Extras\Chain;
// Chain of calls
$res = Chain::chain([1, 2, 3]) // same as Arrays::chain([1, 2, 3])
->map(function($num){ return $num + 1; })
->filter(function($num){ return $num > 1; })
->reduce(function($carry, $num){ return $carry + $num; }, 0)
->value(); // 9
<?php
use Dsheiko\Extras\Chain;
class MapObject
{
public $foo = "FOO";
public $bar = "BAR";
}
$res = Chain::chain(new MapObject)
->keys()
->value(); // ["foo", "bar"]
Binds a then (transformer) function to the chain
{callable} $callable
- then function
{Set}::then($function): Chain
<?php
use Dsheiko\Extras\Chain;
$res = Chain::chain(new \ArrayObject([1,2,3))
// same as Collections::chain(new \ArrayObject([1,2,3])
->toArray()
->then("json_encode")
->value(); // "[1,2,3]"
Underscore syntax for then
{callable} $callable
- then function
{Set}::tap($function): Chain
Extracts the value of a wrapped object.
$chain::value()