Skip to content

Commit 7e8f271

Browse files
committed
change implementation
1 parent 60dd046 commit 7e8f271

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/iterable-functions.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Traversable;
1111

1212
use function array_filter;
13-
use function array_map;
1413
use function array_values;
1514
use function iterator_to_array;
1615

@@ -23,11 +22,9 @@
2322
*/
2423
function iterable_map(iterable $iterable, callable $map): iterable
2524
{
26-
if ($iterable instanceof Traversable) {
27-
return new ArrayIterator(array_map($map, iterator_to_array($iterable)));
25+
foreach ($iterable as $key => $item) {
26+
yield $key => $map($item);
2827
}
29-
30-
return array_map($map, $iterable);
3128
}
3229

3330
/**

0 commit comments

Comments
 (0)