09/03
2016
dev-master
9999999-dev
MIT
The Requires
- php ^7
- nikic/iter ^1.3
The Development Requires
by Prasetyo Wicaksono
Wallogit.com
2017 © Pedro Peláez
This collection implement nikic/iter to provide lazy initialization and operation by using Generator, (*2)
composer require praswicaksono/lazy-collection dev-master, (*3)
$iterable = function () {
for ($i = 1; $i <= 5; $i++) {
yield $i;
}
};
$collection = IterableCollection::fromGenerator($iterable());
$collection = IterableCollection::fromArray([1, 2, 3, 4, 5]);
$iterable = function () {
for ($i = 1; $i <= 5; $i++) {
yield $i;
}
};
$result = IterableCollection::fromGenerator($iterable())
->map(function ($value) {
return $value * 10;
})
->filter(function ($value) {
return $value > 30;
})
->reduce(function ($acc, $value, $startValue) {
return $acc + $value;
});
// $result = 90
For more information, checkout the test suite., (*4)
PRs are welcome!, (*5)
MIT, (*6)
MIT