Skip to content
This repository has been archived by the owner on Jun 20, 2018. It is now read-only.

Commit

Permalink
Merge pull request #17 from kieranajp/hotfix/iterable-enumerable
Browse files Browse the repository at this point in the history
Add PHP7.1 support by renaming Iterable
  • Loading branch information
italolelis committed Dec 13, 2016
2 parents c12e320 + 974c6fd commit 588c272
Show file tree
Hide file tree
Showing 35 changed files with 227 additions and 226 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: php
php:
- 5.6
- 7.0
- 7.1
- nightly
- hhvm

Expand All @@ -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
132 changes: 66 additions & 66 deletions src/Iterable.php → src/Enumerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand All @@ -93,135 +93,135 @@ 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();

/**
* 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();
}
8 changes: 4 additions & 4 deletions src/Iterator/LazyConcatIterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 7 additions & 7 deletions src/Iterator/LazyFilterIterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 5 additions & 5 deletions src/Iterator/LazyFilterKeyedIterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Loading

0 comments on commit 588c272

Please sign in to comment.