Re: RFC Draft: Comprehensions

From: Date: Tue, 19 Mar 2019 22:31:51 +0000
Subject: Re: RFC Draft: Comprehensions
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-104810@lists.php.net to get a copy of this message
On 19/03/2019 20:24, Levi Morrison wrote:
Today in the Dart world, Bob Nystrom published an article called [Making Dart a Better Language for UI][1]. I think it's an incredibly relevant article, since it is essentially about comprehensions, why they are a thing, as well as some of the design choices they made. I think everyone in this thread ought to spend the 10-15 minutes reading it. [1]: https://medium.com/dartlang/making-dart-a-better-language-for-ui-f1ccaf9f546c
Hi Levi, That is indeed a very interesting article, thanks for sharing. The idea of foreach and if just being available whenever you're specifying an array is a really interesting version of this construct. The mention of the spread operator has actually given me a different idea, related to iterator_to_array. What if the "..." operator could spread any iterable, not just arrays as currently proposed in an RFC [1]? $iterator = new SomethingIterator; $array = [ ...$iterator ]; $array2 = [ ...someGenerator() ]; That plus the current comprehension proposal would give us this: $array = [ ...[ foreach $list as $x if $x % 2 yield $x*2] ]; Which could fairly naturally be special cased to this: $array = [ ... foreach $list as $x if $x % 2 yield $x*2 ]; This would give us concise syntax for both iterator and array forms, in a way that fits the rest of the language better than () vs []. [1]: https://wiki.php.net/rfc/spread_operator_for_array -- Rowan Collins [IMSoP]

« previous php.internals (#104810) next »