src/Set.php
public function reduce(callable $callback, $initial = null)
    {
        $carry = $initial;

        foreach ($this as $value) {
            $carry = $callback($carry, $value);
        }

        return $carry;
    }
public function reduce(callable $callback, $initial = null)
    {
        $carry = $initial;

        foreach ($this as $value) {
            $carry = $callback($carry, $value);
        }

        return $carry;
    }
public function reduce ( callable $ callback , $ initial = null ) { $ carry = $ initial ; foreach ( $ this as $ value ) { $ carry = $ callback ( $ carry , $ value ) ; } return $ carry ; }
Iteratively reduces the set to a single value using a callback.

@param callable $callback Accepts the carry and current value, and
returns an updated carry value.

@param mixed|null $initial Optional initial carry value.

@return mixed The carry value of the final iteration, or the initial
value if the set was empty.
Iteratively reduces the set to a single value using a callback .