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

Use loophp/iterators #228

Merged
merged 6 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
}
],
"require": {
"php": ">= 7.4"
"php": ">= 7.4",
"loophp/iterators": "^1.3"
},
"require-dev": {
"amphp/parallel-functions": "^1",
Expand Down
2 changes: 1 addition & 1 deletion spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
use loophp\collection\Collection;
use loophp\collection\Contract\Collection as CollectionInterface;
use loophp\collection\Contract\Operation;
use loophp\collection\Iterator\ClosureIterator;
use loophp\collection\Operation\AbstractOperation;
use loophp\iterators\ClosureIterator;
use OutOfBoundsException;
use PhpSpec\Exception\Example\FailureException;
use PhpSpec\Exception\Example\MatcherException;
Expand Down
55 changes: 0 additions & 55 deletions spec/loophp/collection/Iterator/ArrayCacheIteratorSpec.php

This file was deleted.

95 changes: 0 additions & 95 deletions spec/loophp/collection/Iterator/ClosureIteratorSpec.php

This file was deleted.

87 changes: 0 additions & 87 deletions spec/loophp/collection/Iterator/IterableIteratorSpec.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@

class MultipleIterableIteratorSpec extends ObjectBehavior
{
public function it_can_iterate_with_a_single_iterable(): void
{
$this->beConstructedWith([1, 2, 3]);

$this->getInnerIterator()->shouldIterateAs([1, 2, 3]);
}

public function it_can_iterate_with_multiple_iterables(): void
{
$this->beConstructedWith([1, 2, 3], new ArrayIterator([4, 5, 6]));
Expand All @@ -41,7 +34,7 @@ public function it_can_iterate_with_multiple_iterables(): void
yield 2 => 6;
};

$this->getInnerIterator()->shouldIterateAs($expected());
$this->shouldIterateAs($expected());
}

public function it_is_initializable_with_a_single_iterable(): void
Expand Down
10 changes: 0 additions & 10 deletions spec/loophp/collection/Iterator/PsrCacheIteratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ public function it_can_cache_data(CacheItemPoolInterface $cache): void
->shouldHaveBeenCalledOnce();
}

public function it_can_get_the_inner_iterator(Iterator $iterator, CacheItemPoolInterface $cache): void
{
$this
->beConstructedWith($iterator, $cache);

$this
->getInnerIterator()
->shouldReturn($iterator);
}

public function it_is_initializable(Iterator $iterator, CacheItemPoolInterface $cache): void
{
$this->beConstructedWith($iterator, $cache);
Expand Down
5 changes: 0 additions & 5 deletions spec/loophp/collection/Iterator/RandomIteratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ public function it_can_get_key(): void
$this->key()->shouldReturn('a');
}

public function it_can_get_the_innerIterator(): void
{
$this->getInnerIterator()->shouldBeAnInstanceOf(ArrayIterator::class);
}

public function it_can_next(): void
{
$this->beConstructedWith(new ArrayIterator([1, 2, 3]));
Expand Down
6 changes: 3 additions & 3 deletions spec/loophp/collection/Iterator/ResourceIteratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function it_can_iterate(): void
{
$this->beConstructedWith(fopen('data://text/plain,ABCD', 'rb'));

$this->getInnerIterator()->shouldIterateAs(['A', 'B', 'C', 'D']);
$this->shouldIterateAs(['A', 'B', 'C', 'D']);
}

public function it_closes_opened_file_if_needed(): void
Expand All @@ -30,7 +30,7 @@ public function it_closes_opened_file_if_needed(): void

$this->beConstructedWith($file, true);

$this->getInnerIterator()->shouldIterateAs(['a', 'b', 'c']);
$this->shouldIterateAs(['a', 'b', 'c']);

if (is_resource($file)) {
throw new FailureException('Failed to close resource!');
Expand All @@ -57,7 +57,7 @@ public function it_does_not_close_resource_by_default(): void

$this->beConstructedWith($file);

$this->getInnerIterator()->shouldIterateAs(['a', 'b', 'c']);
$this->shouldIterateAs(['a', 'b', 'c']);

if (!is_resource($file)) {
throw new FailureException('Resource was closed but should not have been!');
Expand Down
4 changes: 2 additions & 2 deletions spec/loophp/collection/Iterator/StringIteratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public function it_can_iterate_with_default_delimiter(): void
{
$this->beConstructedWith('A string.');

$this->getInnerIterator()->shouldIterateAs(['A', ' ', 's', 't', 'r', 'i', 'n', 'g', '.']);
$this->shouldIterateAs(['A', ' ', 's', 't', 'r', 'i', 'n', 'g', '.']);
}

public function it_can_iterate_with_given_delimiter(): void
{
$this->beConstructedWith('I am a string.', ' ');

$this->getInnerIterator()->shouldIterateAs(['I', 'am', 'a', 'string.']);
$this->shouldIterateAs(['I', 'am', 'a', 'string.']);
}

public function it_is_initializable_with_default_delimiter(): void
Expand Down
8 changes: 4 additions & 4 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
use Iterator;
use loophp\collection\Contract\Collection as CollectionInterface;
use loophp\collection\Contract\Operation;
use loophp\collection\Iterator\ArrayCacheIterator;
use loophp\collection\Iterator\ClosureIterator;
use loophp\collection\Iterator\IterableIterator;
use loophp\collection\Iterator\ResourceIterator;
use loophp\collection\Iterator\StringIterator;
use loophp\collection\Operation\All;
Expand Down Expand Up @@ -135,6 +132,9 @@
use loophp\collection\Operation\Words;
use loophp\collection\Operation\Wrap;
use loophp\collection\Operation\Zip;
use loophp\iterators\CachingIteratorAggregate;
use loophp\iterators\ClosureIterator;
use loophp\iterators\IterableIterator;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

Expand Down Expand Up @@ -484,7 +484,7 @@ public static function fromFile(string $filepath): self
public static function fromGenerator(Generator $generator): self
{
return self::fromIterable(
new ArrayCacheIterator(
new CachingIteratorAggregate(
new ClosureIterator(
static function (Generator $generator): Generator {
while ($generator->valid()) {
Expand Down
Loading