Skip to content

Commit

Permalink
Fix creating Collection from Generator
Browse files Browse the repository at this point in the history
  • Loading branch information
JarJak authored Apr 17, 2022
1 parent 4383709 commit b07e6d3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/JarJak/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ public function __construct(...$items)
{
parent::__construct(\count($items));

foreach (array_values($items) as $i => $item) {
$this[$i] = $item;
$i = 0;
foreach ($items as $item) {
$this[$i++] = $item;
}
}

public static function from(iterable $array)
public static function from(iterable $iterable)
{
if (\is_array($array) || $array instanceof \ArrayAccess) {
return new static(...$array);
}

return new static(...$array);
return new static(...$iterable);
}

public function isEmpty(): bool
Expand Down

0 comments on commit b07e6d3

Please sign in to comment.