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

        foreach ($this->pairs as $pair) {
            $carry = $callback($carry, $pair->key, $pair->value);
        }

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

        foreach ($this->pairs as $pair) {
            $carry = $callback($carry, $pair->key, $pair->value);
        }

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

@param callable $callback Accepts the carry, key, and 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 map was empty.
Iteratively reduces the map to a single value using a callback .