-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
Description
Operators like filter and map take an iterable but return an array. All values of the iterable have to be iterated during evaluation. The following example will run out of memory because ints is an infinite iterable:
function ints() {
$counter = 0;
while (true) {
yield $counter;
++$counter;
}
}
$result = Dash\_chain(ints())
->filter('Dash\isEven')
->take(3)
->join(', ')
->value();The same works fine if you use iterables as intermediate results like nikic/iter does
$result = iter\join(', ',
iter\take(3,
iter\filter('Dash\isEven',
ints())));