diff --git a/src/Operation/DropWhile.php b/src/Operation/DropWhile.php index 34b717ac7..cc9b42213 100644 --- a/src/Operation/DropWhile.php +++ b/src/Operation/DropWhile.php @@ -27,13 +27,13 @@ final class DropWhile extends AbstractOperation /** * @pure * - * @return Closure(callable(T, TKey): bool ...): Closure (Iterator): Generator + * @return Closure(callable(T, TKey, Iterator): bool ...): Closure(Iterator): Generator */ public function __invoke(): Closure { return /** - * @param callable(T, TKey):bool ...$callbacks + * @param callable(T, TKey, Iterator):bool ...$callbacks * * @return Closure(Iterator): Generator */ diff --git a/src/Operation/Partition.php b/src/Operation/Partition.php index 550d1a7e4..25de9c4ae 100644 --- a/src/Operation/Partition.php +++ b/src/Operation/Partition.php @@ -31,25 +31,33 @@ final class Partition extends AbstractOperation public function __invoke(): Closure { return - /** - * @param callable(T, TKey, Iterator): bool ...$callbacks - * - * @return Closure(Iterator): Generator): Generator, 1: array{0: Iterator}}> - */ - static fn (callable ...$callbacks): Closure => + ( + /** + * @param array{0:(Closure(callable(T, TKey, Iterator): bool ...): (Closure(Iterator): Generator)), 1:(Closure(callable(T, TKey, Iterator): bool ...): (Closure(Iterator): Generator))} $operations + * + * @return Closure(callable(T, TKey, Iterator): bool ...): Closure(Iterator): Generator): Generator, 1: array{0: Iterator}}> + */ + static fn (array $operations): Closure => + /** + * @param callable(T, TKey, Iterator): bool ...$callbacks + * + * @return Closure(Iterator): Generator): Generator, 1: array{0: Iterator}}> + */ + static fn (callable ...$callbacks): Closure => /** * @param Iterator $iterator * * @return Generator): Generator, 1: array{0: Iterator}}> */ - static function (Iterator $iterator) use ($callbacks): Generator { - /** @var array{0: Closure(Iterator): Generator, 1: array{0: Iterator}} $filter */ - $filter = [Filter::of()(...$callbacks), [$iterator]]; - - /** @var array{0: Closure(Iterator): Generator, 1: array{0: Iterator}} $reject */ - $reject = [Reject::of()(...$callbacks), [$iterator]]; - - return yield from [$filter, $reject]; - }; + static fn (Iterator $iterator): Generator => yield from array_map( + /** + * @param Closure(callable(T, TKey, Iterator): bool ...): (Closure(Iterator): Generator) $callable + * + * @return array{0: (Closure(Iterator): Generator), 1: (array{0: Iterator})} + */ + static fn (callable $callable): array => [$callable(...$callbacks), [$iterator]], + $operations + ) + )([(new Filter())(), (new Reject())()]); } } diff --git a/src/Operation/Span.php b/src/Operation/Span.php index 4e82ed247..401742ebe 100644 --- a/src/Operation/Span.php +++ b/src/Operation/Span.php @@ -31,25 +31,33 @@ final class Span extends AbstractOperation public function __invoke(): Closure { return - /** - * @param callable(T, TKey, Iterator): bool ...$callbacks - * - * @return Closure(Iterator): Generator): Generator, 1: array{0: Iterator}}> - */ - static fn (callable ...$callbacks): Closure => + ( + /** + * @param array{0:(Closure(callable(T, TKey, Iterator): bool ...): (Closure(Iterator): Generator)), 1:(Closure(callable(T, TKey, Iterator): bool ...): (Closure(Iterator): Generator))} $operations + * + * @return Closure(callable(T, TKey, Iterator): bool ...): Closure(Iterator): Generator): Generator, 1: array{0: Iterator}}> + */ + static fn (array $operations): Closure => + /** + * @param callable(T, TKey, Iterator): bool ...$callbacks + * + * @return Closure(Iterator): Generator): Generator, 1: array{0: Iterator}}> + */ + static fn (callable ...$callbacks): Closure => /** * @param Iterator $iterator * * @return Generator): Generator, 1: array{0: Iterator}}> */ - static function (Iterator $iterator) use ($callbacks): Generator { - /** @var array{0: Closure(Iterator): Generator, 1: array{0: Iterator}} $takeWhile */ - $takeWhile = [TakeWhile::of()(...$callbacks), [$iterator]]; - - /** @var array{0: Closure(Iterator): Generator, 1: array{0: Iterator}} $dropWhile */ - $dropWhile = [DropWhile::of()(...$callbacks), [$iterator]]; - - return yield from [$takeWhile, $dropWhile]; - }; + static fn (Iterator $iterator): Generator => yield from array_map( + /** + * @param Closure(callable(T, TKey, Iterator): bool ...): (Closure(Iterator): Generator) $callable + * + * @return array{0: (Closure(Iterator): Generator), 1: (array{0: Iterator})} + */ + static fn (callable $callable): array => [$callable(...$callbacks), [$iterator]], + $operations + ) + )([(new TakeWhile())(), (new DropWhile())()]); } } diff --git a/src/Operation/TakeWhile.php b/src/Operation/TakeWhile.php index 23ce6146e..f5635e111 100644 --- a/src/Operation/TakeWhile.php +++ b/src/Operation/TakeWhile.php @@ -27,7 +27,7 @@ final class TakeWhile extends AbstractOperation /** * @pure * - * @return Closure(callable(T, TKey, Iterator): bool):Closure (Iterator): Generator + * @return Closure(callable(T, TKey, Iterator): bool ...): Closure(Iterator): Generator */ public function __invoke(): Closure {