Skip to content

Commit

Permalink
change implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Feb 4, 2021
1 parent 60dd046 commit 7e8f271
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/iterable-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Traversable;

use function array_filter;
use function array_map;
use function array_values;
use function iterator_to_array;

Expand All @@ -23,11 +22,9 @@
*/
function iterable_map(iterable $iterable, callable $map): iterable
{
if ($iterable instanceof Traversable) {
return new ArrayIterator(array_map($map, iterator_to_array($iterable)));
foreach ($iterable as $key => $item) {
yield $key => $map($item);
}

return array_map($map, $iterable);
}

/**
Expand Down

0 comments on commit 7e8f271

Please sign in to comment.