diff --git a/src/Operation/Collapse.php b/src/Operation/Collapse.php index b77855262..f57b6f0ad 100644 --- a/src/Operation/Collapse.php +++ b/src/Operation/Collapse.php @@ -28,24 +28,19 @@ final class Collapse extends AbstractOperation */ public function __invoke(): Closure { - return + $filterCallback = /** - * @param Iterator|T> $iterator - * - * @return Generator + * @param T $value */ - static function (Iterator $iterator): Generator { - /** @var Closure(Iterator>): Generator> $filter */ - $filter = Filter::of()( - /** - * @param T $value - */ - static fn ($value): bool => is_iterable($value) - ); + static fn ($value): bool => is_iterable($value); - foreach ($filter($iterator) as $value) { - yield from $value; - } - }; + /** @var Closure(Iterator)>): Generator $pipe */ + $pipe = Pipe::of()( + Filter::of()($filterCallback), + Flatten::of()(1), + ); + + // Point free style. + return $pipe; } }