Skip to content

Commit

Permalink
feat: Performance improvements using iterator aggregates.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 24, 2022
1 parent 2f15b72 commit 3b773ad
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 761 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"require": {
"php": ">= 7.4",
"loophp/iterators": "^1.5.6"
"loophp/iterators": "^1.5.8"
},
"require-dev": {
"amphp/parallel-functions": "^1",
Expand Down
6 changes: 3 additions & 3 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use IteratorAggregate;
use loophp\collection\Contract\Collection as CollectionInterface;
use loophp\collection\Contract\Operation;
use loophp\collection\Iterator\ResourceIterator;
use loophp\collection\Operation\All;
use loophp\collection\Operation\Append;
use loophp\collection\Operation\Apply;
Expand Down Expand Up @@ -135,6 +134,7 @@
use loophp\iterators\CachingIteratorAggregate;
use loophp\iterators\ClosureIterator;
use loophp\iterators\IterableIterator;
use loophp\iterators\ResourceIteratorAggregate;
use loophp\iterators\StringIteratorAggregate;
use NoRewindIterator;
use Psr\Cache\CacheItemPoolInterface;
Expand Down Expand Up @@ -470,7 +470,7 @@ public static function fromCallable(callable $callable, iterable $parameters = [
public static function fromFile(string $filepath): self
{
return new self(
static fn (): Iterator => new ResourceIterator(fopen($filepath, 'rb'), true),
static fn (): IteratorAggregate => new ResourceIteratorAggregate(fopen($filepath, 'rb'), true),
);
}

Expand Down Expand Up @@ -515,7 +515,7 @@ public static function fromIterable(iterable $iterable): self
*/
public static function fromResource($resource): self
{
return new self(static fn (): Iterator => new ResourceIterator($resource));
return new self(static fn (): IteratorAggregate => new ResourceIteratorAggregate($resource));
}

/**
Expand Down
91 changes: 0 additions & 91 deletions src/Iterator/ResourceIterator.php

This file was deleted.

131 changes: 0 additions & 131 deletions src/Iterator/TypedIterator.php

This file was deleted.

11 changes: 6 additions & 5 deletions src/Operation/Strict.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

use Closure;
use Iterator;
use loophp\collection\Iterator\TypedIterator;
use IteratorAggregate;
use loophp\iterators\TypedIteratorAggregate;

/**
* @immutable
Expand All @@ -24,22 +25,22 @@ final class Strict extends AbstractOperation
/**
* @pure
*
* @return Closure(null|callable(mixed): string): Closure(Iterator<TKey, T>): Iterator<TKey, T>
* @return Closure(null|callable(mixed): string): Closure(Iterator<TKey, T>): IteratorAggregate<TKey, T>
*/
public function __invoke(): Closure
{
return
/**
* @param null|callable(mixed): string $callback
*
* @return Closure(Iterator<TKey, T>): Iterator<TKey, T>
* @return Closure(Iterator<TKey, T>): IteratorAggregate<TKey, T>
*/
static fn (?callable $callback = null): Closure =>
/**
* @param Iterator<TKey, T> $iterator
*
* @return Iterator<TKey, T>
* @return IteratorAggregate<TKey, T>
*/
static fn (Iterator $iterator): Iterator => new TypedIterator($iterator, $callback);
static fn (Iterator $iterator): IteratorAggregate => new TypedIteratorAggregate($iterator, $callback);
}
}
1 change: 1 addition & 0 deletions tests/unit/CollectionGenericOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
final class CollectionGenericOperationTest extends TestCase
{
use GenericCollectionProviders;

use IterableAssertions;

/**
Expand Down
1 change: 1 addition & 0 deletions tests/unit/CollectionSpecificOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
final class CollectionSpecificOperationTest extends TestCase
{
use GenericCollectionProviders;

use IterableAssertions;

public function testApplyOperation(): void
Expand Down
79 changes: 0 additions & 79 deletions tests/unit/Iterator/ResourceIteratorTest.php

This file was deleted.

Loading

0 comments on commit 3b773ad

Please sign in to comment.