diff --git a/src/Operation/Filter.php b/src/Operation/Filter.php index 6a8a08e8b..89d30e510 100644 --- a/src/Operation/Filter.php +++ b/src/Operation/Filter.php @@ -12,6 +12,7 @@ use Closure; use Generator; use loophp\collection\Utils\CallbacksArrayReducer; +use loophp\iterators\FilterIterableAggregate; /** * @immutable @@ -55,11 +56,7 @@ static function (iterable $iterable) use ($callbacks): Generator { $callback = CallbacksArrayReducer::or()($callbacks); - foreach ($iterable as $key => $current) { - if ($callback($current, $key, $iterable)) { - yield $key => $current; - } - } + yield from new FilterIterableAggregate($iterable, $callback); }; } }