Hi! > Honestly, I cannot think of any case where I'd use a comprehension > where I would definitely want an array and not a generator. In the > majority case both work equally well, cool, but I don't know when I > would even use an array-dependent version.
They wouldn't work equally well. Generator is only sequentially-addressable, and array is random-addressable. And in PHP people do a lot of random addressing of arrays. Also, many functions which accept arrays (and array type) won't work with generators. > And converting from a generator to an array is trivial; the other > way, very not so much. Well, doing everything not using this syntax is trivial - if the point is not doing anything that is already trivial, then we don't need this syntax, as iterating over an array/sequence and applying an operation to it is already trivial in both array and generator contexts, it's a two-liner function in most cases. If the point is to add syntax sugar for most frequently used cases, then I claim that the most frequently used case is definitely not the generator one. I don't think I ever used the generator one in python (I use list one all the time), and I maybe used analogous construct in PHP once or twice (and again I use array_map and more complex syntax for array transformations all the time). BTW, how it's not trivial to make generator from array? function generate($array) { foreach($array as $k => $v) yield $k => $v; } Is there something I'm missing here? -- Stas Malyshev smalys...@gmail.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php