Blueberry
Blueberry copied to clipboard
Generator comprehensions
Like list comprehensions, but produces a generator. Python has these.
I know @gosukiwi stated that we don't want to require PHP 5.5+, but it wouldn't stop people with 5.4 using Blueberry, they just couldn't use generator comprehensions.
Ideal syntax:
-
[2 * i for i in [1..10] where i % 2 == 0]
- list comprehension -
(2 * i for i in [1..10] where i % 2 == 0)
- generator comprehension
I love lazy collections. Generator comprehensions could easily be implemented on PHP 5.5+ using yield
.
result = function($collection) {
foreach($collection as $item) {
yield $item;
}
}
Something I really like of PHP 5.4 is Traits, which would be an elegant way to implement Ruby-like modules. I'll leave this pull request open so anyone willing to implement Generator Comprehensions can submit a pull request :smile:
Generators are a 5.5 thing, not 5.4.
My bad. Fixed it.
Well, Traits are a 5.4 thing. ;)
Them PHP versions :stuck_out_tongue: