phpstreams\Collectors::reducing PHP Méthode

reducing() public static méthode

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

Usage Example

 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