From 8bdcbcadcf61dc698713cdc9eb55937ae70ac108 Mon Sep 17 00:00:00 2001 From: Kieran Date: Tue, 13 Dec 2016 13:25:59 +0100 Subject: [PATCH 1/2] Iterable -> Enumerable for PHP7.1 compat --- src/{Iterable.php => Enumerable.php} | 132 +++++++++--------- src/Iterator/LazyConcatIterable.php | 8 +- src/Iterator/LazyFilterIterable.php | 14 +- src/Iterator/LazyFilterKeyedIterable.php | 10 +- src/Iterator/LazyFilterWithKeyIterable.php | 8 +- src/Iterator/LazyIterableTrait.php | 16 +-- src/Iterator/LazyKeyedIterableTrait.php | 10 +- src/Iterator/LazyKeysIterable.php | 14 +- src/Iterator/LazyMapIterable.php | 14 +- src/Iterator/LazyMapKeyedIterable.php | 8 +- src/Iterator/LazyMapWithKeyIterable.php | 8 +- src/Iterator/LazySkipIterable.php | 14 +- src/Iterator/LazySkipKeyedIterable.php | 8 +- src/Iterator/LazySkipWhileIterable.php | 14 +- src/Iterator/LazySkipWhileKeyedIterable.php | 16 +-- src/Iterator/LazySliceIterable.php | 16 +-- src/Iterator/LazySliceKeyedIterable.php | 8 +- src/Iterator/LazyTakeIterable.php | 14 +- src/Iterator/LazyTakeKeyedIterable.php | 8 +- src/Iterator/LazyTakeWhileIterable.php | 14 +- src/Iterator/LazyTakeWhileKeyedIterable.php | 16 +-- src/Iterator/LazyValuesIterable.php | 14 +- src/Iterator/LazyZipIterable.php | 8 +- src/KeyedIterable.php | 6 +- src/Queue.php | 2 +- src/Stack.php | 2 +- src/Traits/CommonContainerMethodsTrait.php | 8 +- src/Traits/CommonImmMutableContainerTrait.php | 10 +- src/Traits/CommonMutableContainerTrait.php | 10 +- src/Traits/ConstMapLikeTrait.php | 4 +- src/Traits/ConstSetLikeTrait.php | 4 +- src/Traits/ConstVectorLikeTrait.php | 4 +- tests/CollectionsTestCase.php | 2 +- .../{IterableTest.php => EnumerableTest.php} | 6 +- 34 files changed, 225 insertions(+), 225 deletions(-) rename src/{Iterable.php => Enumerable.php} (53%) rename tests/{IterableTest.php => EnumerableTest.php} (97%) diff --git a/src/Iterable.php b/src/Enumerable.php similarity index 53% rename from src/Iterable.php rename to src/Enumerable.php index e6a931b..041fb10 100644 --- a/src/Iterable.php +++ b/src/Enumerable.php @@ -4,55 +4,55 @@ use Collections\Immutable\ImmVector; -interface Iterable extends \IteratorAggregate +interface Enumerable extends \IteratorAggregate { /** - * Returns an array converted from the current Iterable. - * @return array - an array converted from the current Iterable. + * Returns an array converted from the current Enumerable. + * @return array - an array converted from the current Enumerable. */ public function toArray(); /** - * Returns an array with the values from the current Iterable. - * The keys in the current Iterable are discarded and replaced with integer indices, starting with 0. - * @return array - an array containing the values from the current Iterable. + * Returns an array with the values from the current Enumerable. + * The keys in the current Enumerable are discarded and replaced with integer indices, starting with 0. + * @return array - an array containing the values from the current Enumerable. */ public function toValuesArray(); /** - * Returns a Vector converted from the current Iterable. - * Any keys in the current Iterable are discarded and replaced with integer indices, starting with 0. - * @return VectorInterface - a Vector converted from the current Iterable. + * Returns a Vector converted from the current Enumerable. + * Any keys in the current Enumerable are discarded and replaced with integer indices, starting with 0. + * @return VectorInterface - a Vector converted from the current Enumerable. */ public function toVector(); /** - * Returns an immutable vector (`ImmVector`) converted from the current `Iterable`. - * Any keys in the current `Iterable` are discarded and replaced with integer indices, starting with 0. - * @return ImmVector - an `ImmVector` converted from the current `Iterable`. + * Returns an immutable vector (`ImmVector`) converted from the current `Enumerable`. + * Any keys in the current `Enumerable` are discarded and replaced with integer indices, starting with 0. + * @return ImmVector - an `ImmVector` converted from the current `Enumerable`. */ public function toImmVector(); /** - * Returns a `Set` converted from the current `Iterable`. - * Any keys in the current `Iterable` are discarded. - * @return SetInterface - a `Set` converted from the current `Iterable`. + * Returns a `Set` converted from the current `Enumerable`. + * Any keys in the current `Enumerable` are discarded. + * @return SetInterface - a `Set` converted from the current `Enumerable`. */ public function toSet(); /** - * Returns an immutable set (`ImmSet`) converted from the current `Iterable`. - * Any keys in the current `Iterable` are discarded. + * Returns an immutable set (`ImmSet`) converted from the current `Enumerable`. + * Any keys in the current `Enumerable` are discarded. * - * @return ConstSetInterface - an `ImmSet` converted from the current `Iterable`. + * @return ConstSetInterface - an `ImmSet` converted from the current `Enumerable`. */ public function toImmSet(); /** - * Returns an `Iterable` containing the current `Iterable`'s values. + * Returns an `Enumerable` containing the current `Enumerable`'s values. * Any keys are discarded. * - * @return Iterable - An `Iterable` with the values of the current `Iterable`. + * @return Enumerable - An `Enumerable` with the values of the current `Enumerable`. */ public function values(); @@ -63,28 +63,28 @@ public function values(); * * @param callable $fn - A callable function that will receive each of the elements * in this collection - * @return Iterable - The same `Iterable` instance. + * @return Enumerable - The same `Enumerable` instance. */ public function each(callable $fn); /** - * Returns an `Iterable` containing the values after an operation has been - * applied to each value in the current `Iterable`. + * Returns an `Enumerable` containing the values after an operation has been + * applied to each value in the current `Enumerable`. * - * Every value in the current `Iterable` is affected by a call to `map()`, + * Every value in the current `Enumerable` is affected by a call to `map()`, * unlike `filter()` where only values that meet a certain criteria are * affected. * * @param $fn - The callback containing the operation to apply to the - * `Iterable` values. + * `Enumerable` values. * - * @return Iterable - an `Iterable` containing the values after a user-specified + * @return Enumerable - an `Enumerable` containing the values after a user-specified * operation is applied. */ public function map(callable $fn); /** - * Returns an `Iterable` containing the values of the current `Iterable` that + * Returns an `Enumerable` containing the values of the current `Enumerable` that * meet a supplied condition. * * Only values that meet a certain criteria are affected by a call to @@ -93,91 +93,91 @@ public function map(callable $fn); * @param $fn - The callback containing the condition to apply to the * `Itearble` values. * - * @return Iterable - an `Iterable` containing the values after a user-specified + * @return Enumerable - an `Enumerable` containing the values after a user-specified * condition is applied. */ public function filter(callable $fn); /** - * Returns an `Iterable` containing the first `n` values of the current - * `Iterable`. + * Returns an `Enumerable` containing the first `n` values of the current + * `Enumerable`. * - * The returned `Iterable` will always be a proper subset of the current - * `Iterable`. + * The returned `Enumerable` will always be a proper subset of the current + * `Enumerable`. * * `$n` is 1-based. So the first element is 1, the second 2, etc. * * @param $size - The last element that will be included in the returned - * `Iterable`. + * `Enumerable`. * - * @return Iterable - An `Iterable that is a proper subset of the current `Iterable` + * @return Enumerable - An `Enumerable that is a proper subset of the current `Enumerable` * up to `n` elements. */ public function take($size = 1); /** - * Returns an `Iterable` containing the values after the `n`-th element of the - * current `Iterable`. + * Returns an `Enumerable` containing the values after the `n`-th element of the + * current `Enumerable`. * - * The returned `Iterable` will always be a proper subset of the current - * `Iterable`. + * The returned `Enumerable` will always be a proper subset of the current + * `Enumerable`. * * `$n` is 1-based. So the first element is 1, the second 2, etc. * * @param $n - The last element to be skipped; the `$n+1` element will be - * the first one in the returned `Iterable`. + * the first one in the returned `Enumerable`. * - * @return Iterable - An `Iterable` that is a proper subset of the current `Iterable` + * @return Enumerable - An `Enumerable` that is a proper subset of the current `Enumerable` * containing values after the specified `n`-th element. */ public function skip($n); /** - * Returns a subset of the current `Iterable` starting from a given key up + * Returns a subset of the current `Enumerable` starting from a given key up * to, but not including, the element at the provided length from the * starting key. * * `$start` is 0-based. `$len` is 1-based. So `slice(0, 2)` would return the * elements at key 0 and 1. * - * The returned `Iterable` will always be a proper subset of the current - * `Iterable`. + * The returned `Enumerable` will always be a proper subset of the current + * `Enumerable`. * - * @param $start - The starting key of the current `Iterable` to begin the - * returned `Iterable`. - * @param $length - The length of the returned `Iterable`. + * @param $start - The starting key of the current `Enumerable` to begin the + * returned `Enumerable`. + * @param $length - The length of the returned `Enumerable`. * - * @return Iterable - An `Iterable` that is a proper subset of the current `Iterable` + * @return Enumerable - An `Enumerable` that is a proper subset of the current `Enumerable` * starting at `$start` up to but not including the element * `$start + $len`. */ public function slice($start, $length); /** - * Returns an `Iterable` that is the concatenation of the values of the current `Iterable` + * Returns an `Enumerable` that is the concatenation of the values of the current `Enumerable` * and the values of the provided `Traversable`. * - * The values of the provided `Traversable` is concatenated to the end of the current `Iterable` - * to produce the returned `Iterable`. + * The values of the provided `Traversable` is concatenated to the end of the current `Enumerable` + * to produce the returned `Enumerable`. * - * @param \Traversable|array $traversable - The `Traversable` to concatenate to the current `Iterable`. - * @return Iterable - The concatenated `Iterable`. + * @param \Traversable|array $traversable - The `Traversable` to concatenate to the current `Enumerable`. + * @return Enumerable - The concatenated `Enumerable`. */ public function concat($traversable); /** - * Returns the first value in the current `Iterable`. + * Returns the first value in the current `Enumerable`. * - * @return mixed - The first value in the current `Iterable`, or `null` if the - * current `Iterable` is empty. + * @return mixed - The first value in the current `Enumerable`, or `null` if the + * current `Enumerable` is empty. */ public function first(); /** - * Returns the last value in the current `Iterable`. + * Returns the last value in the current `Enumerable`. * - * @return mixed - The last value in the current `Iterable`, or `null` if the - * current `Iterable` is empty. + * @return mixed - The last value in the current `Enumerable`, or `null` if the + * current `Enumerable` is empty. */ public function last(); @@ -185,43 +185,43 @@ public function last(); * Returns a `ConstVector` where each element is a `Pair` that combines the * element of the current `ConstVector` and the provided `Traversable`. * - * If the number of elements of the `Iterable` are not equal to the + * If the number of elements of the `Enumerable` are not equal to the * number of elements in the `Traversable`, then only the combined elements * up to and including the final element of the one with the least number of * elements is included. * * @param $traversable - The `Traversable` to use to combine with the - * elements of this `Iterable`. + * elements of this `Enumerable`. * - * @return - The `Iterable` that combines the values of the current - * `Iterable` with the provided `Traversable`. + * @return - The `Enumerable` that combines the values of the current + * `Enumerable` with the provided `Traversable`. */ public function zip($traversable); /** * Groups the collection based on a given criteria * @param $callback - * @return Iterable + * @return Enumerable */ public function groupBy($callback); /** * Indexes the collection based on a given criteria * @param $callback - * @return Iterable + * @return Enumerable */ public function indexBy($callback); /** * Verifies if an element exists in the collection for a given criteria * @param callable $fn - * @return Iterable + * @return Enumerable */ public function exists(callable $fn); /** * Flatten the collection into one dimension - * @return Iterable + * @return Enumerable */ public function concatAll(); } diff --git a/src/Iterator/LazyConcatIterable.php b/src/Iterator/LazyConcatIterable.php index 6a6db9a..c041ccf 100644 --- a/src/Iterator/LazyConcatIterable.php +++ b/src/Iterator/LazyConcatIterable.php @@ -2,19 +2,19 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazyConcatIterable implements Iterable +class LazyConcatIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ private $iterable1; /** - * @var Iterable + * @var Enumerable */ private $iterable2; diff --git a/src/Iterator/LazyFilterIterable.php b/src/Iterator/LazyFilterIterable.php index 4972402..331e704 100644 --- a/src/Iterator/LazyFilterIterable.php +++ b/src/Iterator/LazyFilterIterable.php @@ -2,30 +2,30 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazyFilterIterable implements Iterable +class LazyFilterIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ - private $iterable; + private $Enumerable; /** * @var callable */ private $fn; - public function __construct($iterable, $fn) + public function __construct($Enumerable, $fn) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->fn = $fn; } public function getIterator() { - return new LazyFilterIterator($this->iterable->getIterator(), $this->fn); + return new LazyFilterIterator($this->Enumerable->getIterator(), $this->fn); } } diff --git a/src/Iterator/LazyFilterKeyedIterable.php b/src/Iterator/LazyFilterKeyedIterable.php index 6b4fbbb..029a29d 100644 --- a/src/Iterator/LazyFilterKeyedIterable.php +++ b/src/Iterator/LazyFilterKeyedIterable.php @@ -11,22 +11,22 @@ class LazyFilterKeyedIterable implements KeyedIterable /** * @var KeyedIterable */ - private $iterable; + private $Enumerable; /** * @var callable */ private $fn; - public function __construct($iterable, $fn) + public function __construct($Enumerable, $fn) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->fn = $fn; } public function getIterator() { return - new LazyFilterKeyedIterator($this->iterable->getIterator(), $this->fn); + new LazyFilterKeyedIterator($this->Enumerable->getIterator(), $this->fn); } -} \ No newline at end of file +} diff --git a/src/Iterator/LazyFilterWithKeyIterable.php b/src/Iterator/LazyFilterWithKeyIterable.php index 01f432f..8e3d52e 100644 --- a/src/Iterator/LazyFilterWithKeyIterable.php +++ b/src/Iterator/LazyFilterWithKeyIterable.php @@ -11,22 +11,22 @@ class LazyFilterWithKeyIterable implements KeyedIterable /** * @var KeyedIterable */ - private $iterable; + private $Enumerable; /** * @var callable */ private $fn; - public function __construct($iterable, $fn) + public function __construct($Enumerable, $fn) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->fn = $fn; } public function getIterator() { return - new LazyFilterWithKeyIterator($this->iterable->getIterator(), $this->fn); + new LazyFilterWithKeyIterator($this->Enumerable->getIterator(), $this->fn); } } diff --git a/src/Iterator/LazyIterableTrait.php b/src/Iterator/LazyIterableTrait.php index ce0159e..6aa94d9 100644 --- a/src/Iterator/LazyIterableTrait.php +++ b/src/Iterator/LazyIterableTrait.php @@ -68,13 +68,13 @@ public function filter(callable $callback) return new LazyFilterIterable($this, $callback); } - public function zip($iterable) + public function zip($Enumerable) { - if (is_array($iterable)) { - $iterable = new ImmMap($iterable); + if (is_array($Enumerable)) { + $Enumerable = new ImmMap($Enumerable); } - return new LazyZipIterable($this, $iterable); + return new LazyZipIterable($this, $Enumerable); } public function take($size = 1) @@ -102,13 +102,13 @@ public function slice($start, $len) return new LazySliceIterable($this, $start, $len); } - public function concat($iterable) + public function concat($Enumerable) { - if (is_array($iterable)) { - $iterable = new ImmMap($iterable); + if (is_array($Enumerable)) { + $Enumerable = new ImmMap($Enumerable); } - return new LazyConcatIterable($this, $iterable); + return new LazyConcatIterable($this, $Enumerable); } public function first() diff --git a/src/Iterator/LazyKeyedIterableTrait.php b/src/Iterator/LazyKeyedIterableTrait.php index 20e61b2..6b1ba50 100644 --- a/src/Iterator/LazyKeyedIterableTrait.php +++ b/src/Iterator/LazyKeyedIterableTrait.php @@ -142,13 +142,13 @@ public function slice($start, $len) return new LazySliceKeyedIterable($this, $start, $len); } - public function concat($iterable) + public function concat($Enumerable) { - if (is_array($iterable)) { - $iterable = new ImmMap($iterable); + if (is_array($Enumerable)) { + $Enumerable = new ImmMap($Enumerable); } - return new LazyConcatIterable($this, $iterable); + return new LazyConcatIterable($this, $Enumerable); } public function first() @@ -274,4 +274,4 @@ public function reduce(callable $callback, $initial = null) return $initial; } -} \ No newline at end of file +} diff --git a/src/Iterator/LazyKeysIterable.php b/src/Iterator/LazyKeysIterable.php index 631e862..b6d15f7 100644 --- a/src/Iterator/LazyKeysIterable.php +++ b/src/Iterator/LazyKeysIterable.php @@ -2,24 +2,24 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazyKeysIterable implements Iterable +class LazyKeysIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ - private $iterable; + private $Enumerable; - public function __construct($iterable) + public function __construct($Enumerable) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; } public function getIterator() { - return new LazyKeysIterator($this->iterable->getIterator()); + return new LazyKeysIterator($this->Enumerable->getIterator()); } } diff --git a/src/Iterator/LazyMapIterable.php b/src/Iterator/LazyMapIterable.php index 72ac0fd..bc66398 100644 --- a/src/Iterator/LazyMapIterable.php +++ b/src/Iterator/LazyMapIterable.php @@ -2,30 +2,30 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazyMapIterable implements Iterable +class LazyMapIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ - private $iterable; + private $Enumerable; /** * @var callable */ private $fn; - public function __construct($iterable, $fn) + public function __construct($Enumerable, $fn) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->fn = $fn; } public function getIterator() { - return new LazyMapIterator($this->iterable->getIterator(), $this->fn); + return new LazyMapIterator($this->Enumerable->getIterator(), $this->fn); } } diff --git a/src/Iterator/LazyMapKeyedIterable.php b/src/Iterator/LazyMapKeyedIterable.php index 1677799..b05eb26 100644 --- a/src/Iterator/LazyMapKeyedIterable.php +++ b/src/Iterator/LazyMapKeyedIterable.php @@ -11,22 +11,22 @@ class LazyMapKeyedIterable implements KeyedIterable /** * @var KeyedIterable */ - private $iterable; + private $Enumerable; /** * @var callable */ private $fn; - public function __construct($iterable, $fn) + public function __construct($Enumerable, $fn) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->fn = $fn; } public function getIterator() { - return new LazyMapKeyedIterator($this->iterable->getIterator(), $this->fn); + return new LazyMapKeyedIterator($this->Enumerable->getIterator(), $this->fn); } } diff --git a/src/Iterator/LazyMapWithKeyIterable.php b/src/Iterator/LazyMapWithKeyIterable.php index b14c659..908eec9 100644 --- a/src/Iterator/LazyMapWithKeyIterable.php +++ b/src/Iterator/LazyMapWithKeyIterable.php @@ -11,22 +11,22 @@ class LazyMapWithKeyIterable implements KeyedIterable /** * @var KeyedIterable */ - private $iterable; + private $Enumerable; /** * @var callable */ private $fn; - public function __construct($iterable, $fn) + public function __construct($Enumerable, $fn) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->fn = $fn; } public function getIterator() { - return new LazyMapWithKeyIterator($this->iterable->getIterator(), $this->fn); + return new LazyMapWithKeyIterator($this->Enumerable->getIterator(), $this->fn); } } diff --git a/src/Iterator/LazySkipIterable.php b/src/Iterator/LazySkipIterable.php index 63c59e1..eba44ce 100644 --- a/src/Iterator/LazySkipIterable.php +++ b/src/Iterator/LazySkipIterable.php @@ -3,31 +3,31 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazySkipIterable implements Iterable +class LazySkipIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ - private $iterable; + private $Enumerable; /** * @var int */ private $n; - public function __construct($iterable, $n) + public function __construct($Enumerable, $n) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->n = $n; } public function getIterator() { - return new LazySkipIterator($this->iterable->getIterator(), $this->n); + return new LazySkipIterator($this->Enumerable->getIterator(), $this->n); } } diff --git a/src/Iterator/LazySkipKeyedIterable.php b/src/Iterator/LazySkipKeyedIterable.php index f10a4fa..8bee3ef 100644 --- a/src/Iterator/LazySkipKeyedIterable.php +++ b/src/Iterator/LazySkipKeyedIterable.php @@ -11,21 +11,21 @@ class LazySkipKeyedIterable implements KeyedIterable /** * @var KeyedIterable */ - private $iterable; + private $Enumerable; /** * @var int */ private $n; - public function __construct($iterable, $n) + public function __construct($Enumerable, $n) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->n = $n; } public function getIterator() { - return new LazySkipKeyedIterator($this->iterable->getIterator(), $this->n); + return new LazySkipKeyedIterator($this->Enumerable->getIterator(), $this->n); } } diff --git a/src/Iterator/LazySkipWhileIterable.php b/src/Iterator/LazySkipWhileIterable.php index 66711ea..1686086 100644 --- a/src/Iterator/LazySkipWhileIterable.php +++ b/src/Iterator/LazySkipWhileIterable.php @@ -2,31 +2,31 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazySkipWhileIterable implements Iterable +class LazySkipWhileIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ - private $iterable; + private $Enumerable; /** * @var callable */ private $fn; - public function __construct($iterable, $fn) + public function __construct($Enumerable, $fn) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->fn = $fn; } public function getIterator() { - return new LazySkipWhileIterator($this->iterable->getIterator(), + return new LazySkipWhileIterator($this->Enumerable->getIterator(), $this->fn); } } diff --git a/src/Iterator/LazySkipWhileKeyedIterable.php b/src/Iterator/LazySkipWhileKeyedIterable.php index 0612a0e..c4dbbc9 100644 --- a/src/Iterator/LazySkipWhileKeyedIterable.php +++ b/src/Iterator/LazySkipWhileKeyedIterable.php @@ -2,30 +2,30 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazySkipWhileKeyedIterable implements Iterable +class LazySkipWhileKeyedIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ - private $iterable; + private $Enumerable; /** * @var callable */ private $fn; - public function __construct($iterable, $fn) + public function __construct($Enumerable, $fn) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->fn = $fn; } public function getIterator() { - return new LazySkipWhileKeyedIterator($this->iterable->getIterator(), $this->fn); + return new LazySkipWhileKeyedIterator($this->Enumerable->getIterator(), $this->fn); } -} \ No newline at end of file +} diff --git a/src/Iterator/LazySliceIterable.php b/src/Iterator/LazySliceIterable.php index 55819ab..f12bdf1 100644 --- a/src/Iterator/LazySliceIterable.php +++ b/src/Iterator/LazySliceIterable.php @@ -2,16 +2,16 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazySliceIterable implements Iterable +class LazySliceIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ - private $iterable; + private $Enumerable; /** * @var int @@ -23,15 +23,15 @@ class LazySliceIterable implements Iterable */ private $len; - public function __construct($iterable, $start, $len) + public function __construct($Enumerable, $start, $len) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->start = $start; $this->len = $len; } public function getIterator() { - return new LazySliceIterator($this->iterable->getIterator(), $this->start, $this->len); + return new LazySliceIterator($this->Enumerable->getIterator(), $this->start, $this->len); } -} \ No newline at end of file +} diff --git a/src/Iterator/LazySliceKeyedIterable.php b/src/Iterator/LazySliceKeyedIterable.php index 623b6b6..ca11f45 100644 --- a/src/Iterator/LazySliceKeyedIterable.php +++ b/src/Iterator/LazySliceKeyedIterable.php @@ -11,7 +11,7 @@ class LazySliceKeyedIterable implements KeyedIterable /** * @var KeyedIterable */ - private $iterable; + private $Enumerable; /** * @var int @@ -23,15 +23,15 @@ class LazySliceKeyedIterable implements KeyedIterable */ private $len; - public function __construct($iterable, $start, $len) + public function __construct($Enumerable, $start, $len) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->start = $start; $this->len = $len; } public function getIterator() { - return new LazySliceKeyedIterator($this->iterable->getIterator(), $this->start, $this->len); + return new LazySliceKeyedIterator($this->Enumerable->getIterator(), $this->start, $this->len); } } diff --git a/src/Iterator/LazyTakeIterable.php b/src/Iterator/LazyTakeIterable.php index 6dbe318..caedd5c 100644 --- a/src/Iterator/LazyTakeIterable.php +++ b/src/Iterator/LazyTakeIterable.php @@ -2,31 +2,31 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazyTakeIterable implements Iterable +class LazyTakeIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ - private $iterable; + private $Enumerable; /** * @var int */ private $n; - public function __construct($iterable, $n) + public function __construct($Enumerable, $n) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->n = $n; } public function getIterator() { - return new LazyTakeIterator($this->iterable->getIterator(), $this->n); + return new LazyTakeIterator($this->Enumerable->getIterator(), $this->n); } } diff --git a/src/Iterator/LazyTakeKeyedIterable.php b/src/Iterator/LazyTakeKeyedIterable.php index 947f369..26fc66f 100644 --- a/src/Iterator/LazyTakeKeyedIterable.php +++ b/src/Iterator/LazyTakeKeyedIterable.php @@ -11,21 +11,21 @@ class LazyTakeKeyedIterable implements KeyedIterable /** * @var KeyedIterable */ - private $iterable; + private $Enumerable; /** * @var int */ private $n; - public function __construct($iterable, $n) + public function __construct($Enumerable, $n) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->n = $n; } public function getIterator() { - return new LazyTakeKeyedIterator($this->iterable->getIterator(), $this->n); + return new LazyTakeKeyedIterator($this->Enumerable->getIterator(), $this->n); } } diff --git a/src/Iterator/LazyTakeWhileIterable.php b/src/Iterator/LazyTakeWhileIterable.php index c31ed8f..6823db0 100644 --- a/src/Iterator/LazyTakeWhileIterable.php +++ b/src/Iterator/LazyTakeWhileIterable.php @@ -3,30 +3,30 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazyTakeWhileIterable implements Iterable +class LazyTakeWhileIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ - private $iterable; + private $Enumerable; /** * @var callable */ private $fn; - public function __construct($iterable, $fn) + public function __construct($Enumerable, $fn) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->fn = $fn; } public function getIterator() { - return new LazyTakeWhileIterator($this->iterable->getIterator(), $this->fn); + return new LazyTakeWhileIterator($this->Enumerable->getIterator(), $this->fn); } } diff --git a/src/Iterator/LazyTakeWhileKeyedIterable.php b/src/Iterator/LazyTakeWhileKeyedIterable.php index 0c7abad..1e00063 100644 --- a/src/Iterator/LazyTakeWhileKeyedIterable.php +++ b/src/Iterator/LazyTakeWhileKeyedIterable.php @@ -2,30 +2,30 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazyTakeWhileKeyedIterable implements Iterable +class LazyTakeWhileKeyedIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ - private $iterable; + private $Enumerable; /** * @var callable */ private $fn; - public function __construct($iterable, $fn) + public function __construct($Enumerable, $fn) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; $this->fn = $fn; } public function getIterator() { - return new LazyTakeWhileKeyedIterator($this->iterable->getIterator(), $this->fn); + return new LazyTakeWhileKeyedIterator($this->Enumerable->getIterator(), $this->fn); } -} \ No newline at end of file +} diff --git a/src/Iterator/LazyValuesIterable.php b/src/Iterator/LazyValuesIterable.php index 669d92f..5190c9f 100644 --- a/src/Iterator/LazyValuesIterable.php +++ b/src/Iterator/LazyValuesIterable.php @@ -2,24 +2,24 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazyValuesIterable implements Iterable +class LazyValuesIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ - private $iterable; + private $Enumerable; - public function __construct($iterable) + public function __construct($Enumerable) { - $this->iterable = $iterable; + $this->Enumerable = $Enumerable; } public function getIterator() { - return new LazyValuesIterator($this->iterable->getIterator()); + return new LazyValuesIterator($this->Enumerable->getIterator()); } } diff --git a/src/Iterator/LazyZipIterable.php b/src/Iterator/LazyZipIterable.php index 97544ea..8448cba 100644 --- a/src/Iterator/LazyZipIterable.php +++ b/src/Iterator/LazyZipIterable.php @@ -2,19 +2,19 @@ namespace Collections\Iterator; -use Collections\Iterable; +use Collections\Enumerable; -class LazyZipIterable implements Iterable +class LazyZipIterable implements Enumerable { use LazyIterableTrait; /** - * @var Iterable + * @var Enumerable */ private $iterable1; /** - * @var Iterable + * @var Enumerable */ private $iterable2; diff --git a/src/KeyedIterable.php b/src/KeyedIterable.php index 6bd2411..f311f41 100644 --- a/src/KeyedIterable.php +++ b/src/KeyedIterable.php @@ -6,7 +6,7 @@ * Interface KeyedIterable * @package Collections */ -interface KeyedIterable extends KeyedTraversable, Iterable +interface KeyedIterable extends KeyedTraversable, Enumerable { /** * Returns an array with the keys from the current `KeyedIterable`. @@ -21,9 +21,9 @@ public function toKeysArray(); public function toMap(); /** - * Returns an `Iterable` containing the current `KeyedIterable`'s keys. + * Returns an `Enumerable` containing the current `KeyedIterable`'s keys. * Any values are discarded. - * @return VectorInterface - `Iterable` with the keys of the current `KeyedIterable`. + * @return VectorInterface - `Enumerable` with the keys of the current `KeyedIterable`. */ public function keys(); diff --git a/src/Queue.php b/src/Queue.php index f7bf2ba..2b5f7f8 100644 --- a/src/Queue.php +++ b/src/Queue.php @@ -45,7 +45,7 @@ public function toArray() { $array = array(); foreach ($this as $key => $value) { - if ($value instanceof Iterable) { + if ($value instanceof Enumerable) { $array[$key] = $value->toArray(); } else { $array[$key] = $value; diff --git a/src/Stack.php b/src/Stack.php index 984f21f..e67db36 100644 --- a/src/Stack.php +++ b/src/Stack.php @@ -45,7 +45,7 @@ public function toArray() { $array = array(); foreach ($this as $key => $value) { - if ($value instanceof Iterable) { + if ($value instanceof Enumerable) { $array[$key] = $value->toArray(); } else { $array[$key] = $value; diff --git a/src/Traits/CommonContainerMethodsTrait.php b/src/Traits/CommonContainerMethodsTrait.php index 666e76e..a64911b 100644 --- a/src/Traits/CommonContainerMethodsTrait.php +++ b/src/Traits/CommonContainerMethodsTrait.php @@ -7,7 +7,7 @@ use Collections\Immutable\ImmVector; use Collections\Immutable\ImmMap; use Collections\Immutable\ImmSet; -use Collections\Iterable; +use Collections\Enumerable; use Collections\Iterator\LazyFilterIterable; use Collections\Iterator\LazyFilterKeyedIterable; use Collections\Iterator\LazyMapIterable; @@ -103,7 +103,7 @@ public function toValuesArray() { $arr = []; foreach ($this as $value) { - if ($value instanceof Iterable) { + if ($value instanceof Enumerable) { $arr[] = $value->toArray(); } else { $arr[] = $value; @@ -130,7 +130,7 @@ public function toArray() { $arr = []; foreach ($this as $key => $value) { - if ($value instanceof Iterable) { + if ($value instanceof Enumerable) { $arr[$key] = $value->toArray(); } else { $arr[$key] = $value; @@ -348,7 +348,7 @@ public function concatAll() { /** @var VectorInterface $results */ $results = new static(); - $this->each(function (Iterable $subArray) use ($results) { + $this->each(function (Enumerable $subArray) use ($results) { $subArray->each(function ($item) use ($results) { $results->add($item); }); diff --git a/src/Traits/CommonImmMutableContainerTrait.php b/src/Traits/CommonImmMutableContainerTrait.php index 0cf4f61..b789fd7 100644 --- a/src/Traits/CommonImmMutableContainerTrait.php +++ b/src/Traits/CommonImmMutableContainerTrait.php @@ -24,14 +24,14 @@ public function keys() /** * {@inheritDoc} */ - public function concat($iterable) + public function concat($Enumerable) { - if (is_array($iterable)) { - $iterable = new ImmVector($iterable); + if (is_array($Enumerable)) { + $Enumerable = new ImmVector($Enumerable); } - if ($iterable instanceof \Traversable) { - return new ImmVector(new LazyConcatIterator($this, $iterable)); + if ($Enumerable instanceof \Traversable) { + return new ImmVector(new LazyConcatIterator($this, $Enumerable)); } else { throw new \InvalidArgumentException('Parameter must be an array or an instance of Traversable'); } diff --git a/src/Traits/CommonMutableContainerTrait.php b/src/Traits/CommonMutableContainerTrait.php index bbb0995..191fa81 100644 --- a/src/Traits/CommonMutableContainerTrait.php +++ b/src/Traits/CommonMutableContainerTrait.php @@ -3,7 +3,7 @@ namespace Collections\Traits; use Collections\Vector; -use Collections\Iterable; +use Collections\Enumerable; use Collections\Iterator\LazyKeysIterable; use Collections\MapInterface; use Collections\Pair; @@ -47,13 +47,13 @@ public function keys() /** * {@inheritDoc} */ - public function concat($iterable) + public function concat($Enumerable) { - if ($iterable instanceof Iterable) { - $iterable = $iterable->toArray(); + if ($Enumerable instanceof Enumerable) { + $Enumerable = $Enumerable->toArray(); } - return new static(array_merge_recursive($this->toArray(), $iterable)); + return new static(array_merge_recursive($this->toArray(), $Enumerable)); } /** diff --git a/src/Traits/ConstMapLikeTrait.php b/src/Traits/ConstMapLikeTrait.php index 547419a..2bd9847 100644 --- a/src/Traits/ConstMapLikeTrait.php +++ b/src/Traits/ConstMapLikeTrait.php @@ -2,7 +2,7 @@ namespace Collections\Traits; -use Collections\Iterable; +use Collections\Enumerable; trait ConstMapLikeTrait { @@ -101,7 +101,7 @@ public function toArray() { $arr = []; foreach ($this as $key => $value) { - if ($value instanceof Iterable) { + if ($value instanceof Enumerable) { $arr[$key] = $value->toArray(); } else { $arr[$key] = $value; diff --git a/src/Traits/ConstSetLikeTrait.php b/src/Traits/ConstSetLikeTrait.php index fb0a098..effc9b5 100644 --- a/src/Traits/ConstSetLikeTrait.php +++ b/src/Traits/ConstSetLikeTrait.php @@ -2,7 +2,7 @@ namespace Collections\Traits; -use Collections\Iterable; +use Collections\Enumerable; trait ConstSetLikeTrait { @@ -86,7 +86,7 @@ public function toArray() { $arr = []; foreach ($this as $k => $v) { - if ($v instanceof Iterable) { + if ($v instanceof Enumerable) { $arr[] = $v->toArray(); } else { $arr[] = $v; diff --git a/src/Traits/ConstVectorLikeTrait.php b/src/Traits/ConstVectorLikeTrait.php index ac7ea5f..dbc2959 100644 --- a/src/Traits/ConstVectorLikeTrait.php +++ b/src/Traits/ConstVectorLikeTrait.php @@ -2,7 +2,7 @@ namespace Collections\Traits; -use Collections\Iterable; +use Collections\Enumerable; trait ConstVectorLikeTrait { @@ -93,7 +93,7 @@ public function toArray() { $arr = []; foreach ($this as $k => $v) { - if ($v instanceof Iterable) { + if ($v instanceof Enumerable) { $arr[] = $v->toArray(); } else { $arr[] = $v; diff --git a/tests/CollectionsTestCase.php b/tests/CollectionsTestCase.php index 22642a4..1c6fa94 100755 --- a/tests/CollectionsTestCase.php +++ b/tests/CollectionsTestCase.php @@ -8,7 +8,7 @@ namespace Tests\Collections; -use Collections\Iterable; +use Collections\Enumerable; use Collections\Map; use Collections\MapInterface; use Collections\Pair; diff --git a/tests/IterableTest.php b/tests/EnumerableTest.php similarity index 97% rename from tests/IterableTest.php rename to tests/EnumerableTest.php index bf83522..ce4bbd9 100755 --- a/tests/IterableTest.php +++ b/tests/EnumerableTest.php @@ -2,12 +2,12 @@ namespace Tests\Collections; -use Collections\Iterable; +use Collections\Enumerable; use Collections\Map; use Collections\Set; use Collections\Vector; -class IterableTest extends CollectionsTestCase +class EnumerableTest extends CollectionsTestCase { protected function setUpCollection() { @@ -129,7 +129,7 @@ public function it_should_take_2_elements() * @test * @dataProvider filterProvider */ - public function it_should_filter_successfully(Iterable $coll, $expected) + public function it_should_filter_successfully(Enumerable $coll, $expected) { $coll = $coll->filter(function ($item) { return $item > 1; From 974c6fd1b1873a0abc4a54cee3128b39f128e4f5 Mon Sep 17 00:00:00 2001 From: Kieran Date: Tue, 13 Dec 2016 13:26:32 +0100 Subject: [PATCH 2/2] Add 7.1 to travis --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bfea510..dd2fd69 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: php php: - 5.6 - 7.0 + - 7.1 - nightly - hhvm @@ -17,6 +18,6 @@ before_script: script: - phpunit --coverage-clover build/logs/clover.xml --configuration ./phpunit.xml.dist ./tests - + after_script: - php bin/codacycoverage clover build/logs/clover.xml