Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Revert "[8.x] Allow lazy collection to be instantiated from a generator" #36844

Merged
merged 1 commit into from
Apr 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/Illuminate/Collections/LazyCollection.php
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
use ArrayIterator;
use Closure;
use DateTimeInterface;
use Generator;
use Illuminate\Support\Traits\EnumeratesValues;
use Illuminate\Support\Traits\Macroable;
use IteratorAggregate;
@@ -30,7 +29,7 @@ class LazyCollection implements Enumerable
*/
public function __construct($source = null)
{
if ($source instanceof Closure || $source instanceof Generator || $source instanceof self) {
if ($source instanceof Closure || $source instanceof self) {
$this->source = $source;
} elseif (is_null($source)) {
$this->source = static::empty();
@@ -1365,10 +1364,6 @@ public function count()
*/
protected function makeIterator($source)
{
if ($source instanceof Generator) {
return $source;
}

if ($source instanceof IteratorAggregate) {
return $source->getIterator();
}
25 changes: 0 additions & 25 deletions tests/Support/SupportLazyCollectionTest.php
Original file line number Diff line number Diff line change
@@ -69,31 +69,6 @@ public function testCanCreateCollectionFromClosure()
], $data->all());
}

public function testCanCreateCollectionFromGenerator()
{
$iterable = function () {
yield 1;
yield 2;
yield 3;
};
$data = LazyCollection::make($iterable());

$this->assertSame([1, 2, 3], $data->all());

$iterable = function () {
yield 'a' => 1;
yield 'b' => 2;
yield 'c' => 3;
};
$data = LazyCollection::make($iterable());

$this->assertSame([
'a' => 1,
'b' => 2,
'c' => 3,
], $data->all());
}

public function testEager()
{
$source = [1, 2, 3, 4, 5];