for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace Zalas\Collection;
use Closure;
use Traversable;
final class LazyCollection implements Collection
{
private $elements;
public function __construct(Traversable $elements)
$this->elements = $elements;
}
public function getIterator(): Traversable
yield from $this->elements;
public function merge(Collection $other): Collection
return self::createFromClosure(function () use ($other) {
foreach ($this as $e) {
yield $e;
foreach ($other as $e) {
});
public function filter(callable $f): Collection
return self::createFromClosure(function () use ($f) {
if ($f($e)) {
public function map(callable $f): Collection
yield $f($e);
/**
* @param mixed $initial
* @param callable $f
*
* @return mixed
*/
public function reduce($initial, callable $f)
return \array_reduce(\iterator_to_array($this), $f, $initial);
private static function createFromClosure(Closure $f): Collection
return new self($f());