On Fri, Mar 17, 2017 at 8:40 PM, David Rodrigues <david.pro...@gmail.com> wrote: > There are some way to PHP be flagged before run some function, and > understand that you wants to return a Generator instead of array? > For instance: new Generator(range(1, 1000)) makes range() work like a > generator instead of return an array - it's an alternative to avoid new > keywords. > Or, maybe, some side implementation like Generator::range(1, 1000), > Generator::array_values($array), etc. (Currently, for instance, we can > simulate the range() Generator, but not array_values()) > Why would array_values() as a generator be difficult?
function generate_values(Traversable $in) { foreach ($in as $k => $v) { yield $k => $v; } } In general, your `new Generator($arr)` concept misses most of the usefulness of using a generator since arrays are already traversable, and you've already allocated all the space of a full container. Where's the benefit from making it a generator? -Sara -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php