Skip to content

Commit

Permalink
Update Filter operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Aug 21, 2020
1 parent a8dac33 commit f81494a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Operation/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ public function __invoke(): Closure
* @psalm-return \Generator<TKey, T>
*/
static function (Iterator $iterator, array $callbacks): Generator {
foreach ($callbacks as $callback) {
$iterator = new CallbackFilterIterator($iterator, $callback);
}

return yield from $iterator;
yield from array_reduce(
$callbacks,
static function (Iterator $carry, callable $callback): CallbackFilterIterator {
return new CallbackFilterIterator($carry, $callback);
},
$iterator
);
};
}
}

0 comments on commit f81494a

Please sign in to comment.