phpstreams\Collectors::reducing PHP Method

reducing() public static method

Get a collector that applies the given reduction to the stream.
public static reducing ( mixed $identity, callable $reduction ) : phpstreams\Collector
$identity mixed
$reduction callable
return phpstreams\Collector
    public static function reducing($identity, callable $reduction)
    {
        return new ReducingCollector($identity, $reduction);
    }

Usage Example

Example #1
0
 public function testReducing()
 {
     $instance = Collectors::reducing(1, function ($a, $b) {
         return $a * $b;
     });
     $instance->add("foo", 2);
     $instance->add("bar", 3);
     $instance->add("baz", 4);
     $this->assertEquals(24, $instance->get());
 }
All Usage Examples Of phpstreams\Collectors::reducing