for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Collections\Traits;
use Collections\Iterable;
use Collections\VectorInterface;
trait StrictIterableTrait
{
use CommonMutableContainerTrait;
/**
* {@inheritDoc}
* @return $this
*/
public function map(callable $callable)
$res = new static();
foreach ($this as $v) {
$this
this<Collections\Traits\StrictIterableTrait>
$res[] = $callable($v);
}
return $res;
public function filter(callable $callable)
if ($callable($v)) {
$res[] = $v;
public function zip(Iterable $iterable)
$it = $iterable->getIterator();
if (!$it->valid()) {
break;
$res[] = new Pair($v, $it->current());
$it->next();
public function take($size = 1)
if ($size <= 0) {
if (--$size === 0) {
public function takeWhile(callable $callable)
if (!$callable($v)) {
public function skip($n)
if ($n <= 0) {
} else {
--$n;
public function skipWhile(callable $callable)
$skip = true;
if ($skip) {
continue;
$skip = false;
public function slice($start, $length)
if ($length <= 0) {
if ($start !== 0) {
--$start;
if (--$length === 0) {
public function concat(\Traversable $iterable)
$res = [];
foreach ($iterable as $v) {
$this->container = $res;
container
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
return $this;
public function first()
return $v;
return null;
public function last()
$result = $this->toArray();
return array_pop($result);
public function each(callable $callable)
$callable($v);
* {@inheritdoc}
public function exists(callable $fn)
foreach ($this as $element) {
if ($fn($element)) {
return true;
return false;
public function concatAll()
/** @var VectorInterface $results */
$results = new static();
$this->each(function (Iterable $subArray) use ($results) {
$subArray->each(function ($item) use ($results) {
$results->add($item);
});
return $results;