Skip to content

Commit

Permalink
[10.x] Fixes Exception: Cannot traverse an already closed generator w…
Browse files Browse the repository at this point in the history
…hen running Arr::first with an empty generator and no callback (#48979)

* fix Exception: Cannot traverse an already closed generator when running Arr::first with an empty generator and no callback

* force rerun actions

* force rerun actions
  • Loading branch information
moshe-autoleadstar authored Nov 13, 2023
1 parent 3cb7ed2 commit 0a30702
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Collections/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public static function first($array, callable $callback = null, $default = null)
foreach ($array as $item) {
return $item;
}

return value($default);
}

foreach ($array as $key => $value) {
Expand Down
7 changes: 7 additions & 0 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ public function testFirst()
$this->assertSame('bar', $value3);
$this->assertSame('baz', $value4);
$this->assertEquals(100, $value5);

$cursor = (function () {
while (false) {
yield 1;
}
})();
$this->assertNull(Arr::first($cursor));
}

public function testJoin()
Expand Down

0 comments on commit 0a30702

Please sign in to comment.