diff --git a/spec/loophp/collection/CollectionSpec.php b/spec/loophp/collection/CollectionSpec.php index 4038016fb..381a9e59a 100644 --- a/spec/loophp/collection/CollectionSpec.php +++ b/spec/loophp/collection/CollectionSpec.php @@ -302,18 +302,39 @@ public function it_can_be_constructed_from_empty(): void public function it_can_be_constructed_with_a_closure(): void { - $this - ->beConstructedThrough('fromCallable', [ - static function (int $a, int $b): Generator { - return yield from range($a, $b); - }, - 1, - 5, - ]); + $test = $this::fromCallable( + static function (int $a, int $b): Generator { + return yield from range($a, $b); + }, + 1, + 5, + ); - $this->shouldImplement(Collection::class); + $test->shouldImplement(Collection::class); - $this + $test + ->getIterator() + ->shouldIterateAs( + [ + 1, + 2, + 3, + 4, + 5, + ] + ); + + $test = $this::fromCallable( + static function (int $a, int $b): array { + return range($a, $b); + }, + 1, + 5, + ); + + $test->shouldImplement(Collection::class); + + $test ->getIterator() ->shouldIterateAs( [ diff --git a/src/Collection.php b/src/Collection.php index 9c62773db..5dc7c5754 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -7,7 +7,6 @@ use Closure; use Generator; use Iterator; -use IteratorIterator; use loophp\collection\Contract\Collection as CollectionInterface; use loophp\collection\Contract\Operation; use loophp\collection\Iterator\ClosureIterator; @@ -351,17 +350,7 @@ public function frequency(): CollectionInterface public static function fromCallable(callable $callable, ...$parameters): self { - return new self( - /** - * @psalm-param callable(T...) $callable - * @psalm-param list $parameters - * - * @psalm-return Iterator - */ - static fn (callable $callable, array $parameters): Iterator => new IteratorIterator($callable(...$parameters)), - $callable, - $parameters - ); + return new self($callable, ...$parameters); } public static function fromFile(string $filepath): self