Skip to content

Commit

Permalink
Replace Iterator with iterable almost everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 28, 2022
1 parent 19616a6 commit d623bc4
Show file tree
Hide file tree
Showing 122 changed files with 533 additions and 632 deletions.
4 changes: 2 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
use loophp\collection\Operation\Zip;
use loophp\iterators\CachingIteratorAggregate;
use loophp\iterators\ClosureIterator;
use loophp\iterators\IterableIterator;
use loophp\iterators\IterableIteratorAggregate;
use loophp\iterators\ResourceIteratorAggregate;
use loophp\iterators\StringIteratorAggregate;
use NoRewindIterator;
Expand Down Expand Up @@ -503,7 +503,7 @@ public static function fromGenerator(Generator $generator): self
*/
public static function fromIterable(iterable $iterable): self
{
return new self(static fn (): Iterator => new IterableIterator($iterable));
return new self(static fn (): IteratorAggregate => new IterableIteratorAggregate($iterable));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/Applyable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -25,7 +24,7 @@ interface Applyable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#apply
*
* @param callable(T=, TKey=, Iterator<TKey, T>=): bool ...$callbacks
* @param callable(T=, TKey=, iterable<TKey, T>=): bool ...$callbacks
*
* @return Collection<TKey, T>
*/
Expand Down
10 changes: 3 additions & 7 deletions src/Contract/Operation/Associateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -23,13 +22,10 @@ interface Associateable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#associate
*
* @template NewT
* @template NewTKey
* @param callable(TKey=, T=, iterable<TKey, T>=): mixed $callbackForKeys
* @param callable(T=, TKey=, iterable<TKey, T>=): mixed $callbackForValues
*
* @param callable(TKey=, T=, Iterator<TKey, T>=): NewTKey $callbackForKeys
* @param callable(T=, TKey=, Iterator<TKey, T>=): NewT $callbackForValues
*
* @return Collection<NewTKey, NewT>
* @return Collection<mixed, mixed>
*/
public function associate(?callable $callbackForKeys = null, ?callable $callbackForValues = null): Collection;
}
6 changes: 2 additions & 4 deletions src/Contract/Operation/Duplicateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ interface Duplicateable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#duplicate
*
* @template U
*
* @param null|callable(U): (Closure(U): bool) $comparatorCallback
* @param null|callable(T, TKey): U $accessorCallback
* @param (callable(mixed): (Closure(mixed): bool)) $comparatorCallback
* @param callable(T, TKey): mixed $accessorCallback
*
* @return Collection<TKey, T>
*/
Expand Down
4 changes: 1 addition & 3 deletions src/Contract/Operation/Everyable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;

/**
* @template TKey
* @template T
Expand All @@ -22,7 +20,7 @@ interface Everyable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#every
*
* @param callable(T=, TKey=, Iterator<TKey, T>=): bool ...$callbacks
* @param callable(T=, TKey=, iterable<TKey, T>=): bool ...$callbacks
*/
public function every(callable ...$callbacks): bool;
}
3 changes: 1 addition & 2 deletions src/Contract/Operation/Filterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -23,7 +22,7 @@ interface Filterable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#filter
*
* @param callable(T=, TKey=, Iterator<TKey, T>=): bool ...$callbacks
* @param callable(T=, TKey=, iterable<TKey, T>=): bool ...$callbacks
*
* @return Collection<TKey, T>
*/
Expand Down
4 changes: 1 addition & 3 deletions src/Contract/Operation/Findable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;

/**
* @template TKey
* @template T
Expand All @@ -26,7 +24,7 @@ interface Findable
* @template V
*
* @param V $default
* @param (callable(T=, TKey=, Iterator<TKey, T>=): bool) ...$callbacks
* @param (callable(T=, TKey=, iterable<TKey, T>=): bool) ...$callbacks
*
* @return T|V
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/FlatMapable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -27,7 +26,7 @@ interface FlatMapable
* @template IKey
* @template IValue
*
* @param callable(T=, TKey=, Iterator<TKey, T>=): iterable<IKey, IValue> $callback
* @param callable(T=, TKey=, iterable<TKey, T>=): iterable<IKey, IValue> $callback
*
* @return Collection<IKey, IValue>
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/FoldLeftable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -24,7 +23,7 @@ interface FoldLeftable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#foldleft
*
* @param callable(T, T, TKey, Iterator<TKey, T>): T $callback
* @param callable(T, T, TKey, iterable<TKey, T>): T $callback
* @param T|null $initial
*
* @return Collection<TKey, T|null>
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/FoldRightable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -24,7 +23,7 @@ interface FoldRightable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#foldright
*
* @param callable(T, T, TKey, Iterator<TKey, T>): T $callback
* @param callable(T, T, TKey, iterable<TKey, T>): T $callback
* @param T|null $initial
*
* @return Collection<TKey, T|null>
Expand Down
4 changes: 1 addition & 3 deletions src/Contract/Operation/Hasable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;

/**
* @template TKey
* @template T
Expand All @@ -22,7 +20,7 @@ interface Hasable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#has
*
* @param callable(T=, TKey=, Iterator<TKey, T>=): T ...$callbacks
* @param callable(T=, TKey=, iterable<TKey, T>=): T ...$callbacks
*/
public function has(callable ...$callbacks): bool;
}
3 changes: 1 addition & 2 deletions src/Contract/Operation/MapNable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -23,7 +22,7 @@ interface MapNable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#mapn
*
* @param callable(mixed, mixed, Iterator<TKey, T>): mixed ...$callbacks
* @param callable(mixed, mixed, iterable<TKey, T>): mixed ...$callbacks
*
* @return Collection<mixed, mixed>
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/Mapable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -25,7 +24,7 @@ interface Mapable
*
* @template V
*
* @param callable(T=, TKey=, Iterator<TKey, T>=): V $callback
* @param callable(T=, TKey=, iterable<TKey, T>=): V $callback
*
* @return Collection<TKey, V>
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Contract/Operation/Matchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ interface Matchable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#match
*
* @param callable(T=, TKey=, Iterator<TKey, T>=): bool $callback
* @param null|callable(T=, TKey=, Iterator<TKey, T>=): bool $matcher
* @param callable(T=, TKey=, iterable<TKey, T>=): bool $callback
* @param null|callable(T=, TKey=, iterable<TKey, T>=): bool $matcher
*/
public function match(callable $callback, ?callable $matcher = null): bool;
}
3 changes: 1 addition & 2 deletions src/Contract/Operation/Partitionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -26,7 +25,7 @@ interface Partitionable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#partition
*
* @param callable(T=, TKey=, Iterator<TKey, T>=): bool ...$callbacks
* @param callable(T=, TKey=, iterable<TKey, T>=): bool ...$callbacks
*
* @return Collection<int, Collection<TKey, T>>
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/Reduceable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -26,7 +25,7 @@ interface Reduceable
* @template V
* @template W
*
* @param callable((V|W)=, T=, TKey=, Iterator<TKey, T>=): W $callback
* @param callable((V|W)=, T=, TKey=, iterable<TKey, T>=): W $callback
* @param V $initial
*
* @return Collection<TKey, W>
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/Reductionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -26,7 +25,7 @@ interface Reductionable
* @template V
* @template W
*
* @param callable((V|W)=, T=, TKey=, Iterator<TKey, T>=): W $callback
* @param callable((V|W)=, T=, TKey=, iterable<TKey, T>=): W $callback
* @param V $initial
*
* @return Collection<TKey, W>
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/Rejectable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -23,7 +22,7 @@ interface Rejectable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#reject
*
* @param callable(T=, TKey=, Iterator<TKey, T>=): bool ...$callbacks
* @param callable(T=, TKey=, iterable<TKey, T>=): bool ...$callbacks
*
* @return Collection<TKey, T>
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/ScanLeftable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -28,7 +27,7 @@ interface ScanLeftable
* @template V
* @template W
*
* @param callable((V|W)=, T=, TKey=, Iterator<TKey, T>=): W $callback
* @param callable((V|W)=, T=, TKey=, iterable<TKey, T>=): W $callback
* @param V $initial
*
* @return Collection<int|TKey, V|W>
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/ScanRightable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -28,7 +27,7 @@ interface ScanRightable
* @template V
* @template W
*
* @param callable((V|W)=, T=, TKey=, Iterator<TKey, T>=): W $callback
* @param callable((V|W)=, T=, TKey=, iterable<TKey, T>=): W $callback
* @param V $initial
*
* @return Collection<int|TKey, V|W>
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/Spanable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -27,7 +26,7 @@ interface Spanable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#span
*
* @param callable(T=, TKey=, Iterator<TKey, T>=): bool ...$callbacks
* @param callable(T=, TKey=, iterable<TKey, T>=): bool ...$callbacks
*
* @return Collection<int, Collection<TKey, T>>
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/Operation/TakeWhileable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -24,7 +23,7 @@ interface TakeWhileable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#takewhile
*
* @param callable(T=, TKey=, Iterator<TKey, T>=): bool ...$callbacks
* @param callable(T=, TKey=, iterable<TKey, T>=): bool ...$callbacks
*
* @return Collection<TKey, T>
*/
Expand Down
7 changes: 3 additions & 4 deletions src/Contract/Operation/Whenable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -27,9 +26,9 @@ interface Whenable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#when
*
* @param callable(Iterator<TKey, T>): bool $predicate
* @param callable(Iterator<TKey, T>): iterable<TKey, T> $whenTrue
* @param callable(Iterator<TKey, T>): iterable<TKey, T> $whenFalse
* @param callable(iterable<TKey, T>): bool $predicate
* @param callable(iterable<TKey, T>): iterable<TKey, T> $whenTrue
* @param callable(iterable<TKey, T>): iterable<TKey, T> $whenFalse
*
* @return Collection<TKey, T>
*/
Expand Down
Loading

0 comments on commit d623bc4

Please sign in to comment.