diff options
-rw-r--r-- | it.class | 2 | ||||
-rwxr-xr-x | test/it.t | 3 |
2 files changed, 4 insertions, 1 deletions
@@ -1111,7 +1111,7 @@ static function map($code, $array, $p = null) { $func = self::createfunc($code); $result = is_array($array) ? $array : iterator_to_array($array); - foreach (isset($p['keys']) ? it::filter_keys($array, $p['keys']) : $array as $k => $v) + foreach (isset($p['keys']) ? it::filter_keys($result, $p['keys']) : $result as $k => $v) $result[$k] = $func($k, $v); return (array)$result; @@ -490,6 +490,9 @@ is(it::map('it::ucfirst', ["aaa"]), ["Aaa"]); $dom = new DOMDocument; $dom->loadXML('<foo>42</foo>'); is(it::map('$v->C14N()', $dom->childNodes), [ '<foo>42</foo>' ], "Traversable: Needs copy, not modifiable in-place"); +# Generator function +function _generator() { foreach (range(1,2) as $v) yield $v; } +is(it::map('2*$v', _generator()), [2, 4], "Generator"); # Special values which are not callable is(it::map('null', ["aaa", "aa"]), [null, null]); is(it::map('1', ["aaa", "aa"]), [1, 1]); |