diff --git a/spec/loophp/collection/CollectionSpec.php b/spec/loophp/collection/CollectionSpec.php index a7ba30d21..01efd3dd5 100644 --- a/spec/loophp/collection/CollectionSpec.php +++ b/spec/loophp/collection/CollectionSpec.php @@ -2254,6 +2254,18 @@ public function it_can_pair(): void ->unwrap() ->pair() ->shouldIterateAs($gen()); + + $input = ['a', 'b', 'c']; + + $gen = static function () { + yield 'a' => 'b'; + + yield 'c' => null; + }; + + $this::fromIterable($input) + ->pair() + ->shouldIterateAs($gen()); } public function it_can_partition(): void diff --git a/src/Operation/Pair.php b/src/Operation/Pair.php index 576703d23..df7c60bb9 100644 --- a/src/Operation/Pair.php +++ b/src/Operation/Pair.php @@ -34,9 +34,9 @@ public function __invoke(): Closure * @param TKey $key * @param array{0: TKey, 1: T} $value * - * @return T|TKey + * @return T|TKey|null */ - static fn ($initial, $key, array $value) => $value[0]; + static fn ($initial, $key, array $value) => $value[0] ?? null; $callbackForValues = /** @@ -44,9 +44,9 @@ public function __invoke(): Closure * @param TKey $key * @param array{0: TKey, 1: T} $value * - * @return T|TKey + * @return T|TKey|null */ - static fn ($initial, $key, array $value) => $value[1]; + static fn ($initial, $key, array $value) => $value[1] ?? null; /** @var Closure(Iterator): Generator $pipe */ $pipe = Pipe::of()(