Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Generator comprehensions #34

Open
hikari-no-yume opened this issue Jan 10, 2015 · 5 comments
Open

Generator comprehensions #34

hikari-no-yume opened this issue Jan 10, 2015 · 5 comments

Comments

@hikari-no-yume
Copy link
Contributor

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
@gosukiwi
Copy link
Owner

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 😄

@hikari-no-yume
Copy link
Contributor Author

Generators are a 5.5 thing, not 5.4.

@gosukiwi
Copy link
Owner

My bad. Fixed it.

@hikari-no-yume
Copy link
Contributor Author

Well, Traits are a 5.4 thing. ;)

@gosukiwi
Copy link
Owner

Them PHP versions 😛

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants