From 58fd5dad84e121417ccc9ef90afe5d1acad0114d Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 1 Dec 2023 11:03:06 +0100 Subject: [PATCH] fix: `pair` and `chunk` operation when using empty input (#327) Fix https://github.com/loophp/collection/issues/326 --- src/Operation/Chunk.php | 4 +++- tests/unit/Traits/GenericCollectionProviders.php | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Operation/Chunk.php b/src/Operation/Chunk.php index 333f280a4..81e6838fe 100644 --- a/src/Operation/Chunk.php +++ b/src/Operation/Chunk.php @@ -59,7 +59,9 @@ static function (iterable $iterable) use ($sizes): Generator { $values = [$value]; } - yield $values; + if ([] !== $values) { + yield $values; + } }; } } diff --git a/tests/unit/Traits/GenericCollectionProviders.php b/tests/unit/Traits/GenericCollectionProviders.php index 423bbbca7..15dcfdb6a 100644 --- a/tests/unit/Traits/GenericCollectionProviders.php +++ b/tests/unit/Traits/GenericCollectionProviders.php @@ -3220,6 +3220,13 @@ public static function pairOperationProvider() $input, $output(), ]; + + yield [ + $operation, + [], + [], + [], + ]; } public static function permutateOperationProvider()