zalas / collections
This package is abandoned and no longer maintained.
No replacement package was suggested.
A tiny collection library
v1.1.0
2020-04-06 20:46 UTC
Requires
- php: ^7.3
Requires (Dev)
- phpunit/phpunit: ^9.1
This package is auto-updated.
Last update: 2022-03-07 01:06:36 UTC
README
A tiny collection library enabling array_*
like operations on generators and other traversables.
Collection interface
interface Collection extends IteratorAggregate { public function merge(Collection $other): Collection; public function filter(callable $f): Collection; public function map(callable $f): Collection; /** * @param mixed $initial * @param callable $f * * @return mixed */ public function reduce($initial, callable $f); }
Collection implementations
LazyCollection
The lazy collection implementation postpones evaluation of elements until it's necessary.
use Zalas\Collection\LazyCollection; $c = (new LazyCollection(new \ArrayIterator([1, 2, 3, 4]))) ->filter(fn (int $e) => 0 === $e % 2) ->map(fn (int $e) => $e * 2) ;
In legacy PHP versions:
use Zalas\Collection\LazyCollection; $c = (new LazyCollection(new \ArrayIterator([1, 2, 3, 4))) ->filter(function (int $e) { return 0 === $e % 2; }) ->map(function (int $e) { return $e * 2; }) ;
Installation
composer require zalas/collections
Contributing
Please read the Contributing guide to learn about contributing to this project. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.