nikic / iter

Iteration primitives using generators
Other
1.12k stars 76 forks source link

Added 'key' parameter into callable for 'reduce' and 'reductions' functions #28

Closed alxsad closed 9 years ago

alxsad commented 9 years ago
iter\reduce(function ($acc, $value, $key) {
    $acc .= sprintf("%s: %s\n", $key, $value);
    return $acc;
}, $response->headers->all(), '');
nikic commented 9 years ago

Merged via https://github.com/nikic/iter/commit/5527ca489bf151ceef17622f1c89114640f522d2, thanks! Note that this is a BC breaking change, because internal functions do not allow additional arguments.

Maybe we should also extend this (providing a $key) to other functions in the library. Functions where this would seem reasonable are map, filter, apply, any, all, search, takeWhile, dropWhile. One weird case is mapKeys/reindex -- this is the same function, with one accepting only key and the other only value.