Thanks Rowan. IMO it's very natural to try to apply operators to similar 
scenario, array construction in this case, and I'm completing the missing piece 
of jigsaw puzzle.

Here is a MDN document for spread operator in JS: 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#Spread_in_array_literals
 and hope you find more useful examples.

TL;DR: this RFC is not making something impossible to become possible, it's 
making something not so easy to become easy and efficient.

-----Original Message-----
From: Rowan Collins <rowan.coll...@gmail.com> 
Sent: Friday, April 5, 2019 12:40 AM
To: Derick Rethans <der...@php.net>
Cc: CHU Zhaowei <m...@jhdxr.com>; PHP internals <internals@lists.php.net>
Subject: Re: [PHP-DEV] [RFC] Spread Operator in Array Expression v0.2

On Thu, 4 Apr 2019 at 17:14, Derick Rethans <der...@php.net> wrote:

> Could you add to the RFC what the exact pain point is that this is 
> trying to address? It looks a little like this is just adding syntax 
> for the sake of it.
>


Not everything is about pain, some things are just about gain. ;)

The link Levi shared about Dart included some interesting examples of where 
spreads are useful, some of which you can probably imagine happening in
PHP:
https://medium.com/dartlang/making-dart-a-better-language-for-ui-f1ccaf9f546c

It also takes us a step closer to having a short-hand for iterator_to_array, in 
the shape of [...$iterator]. On its own, that's still pretty ugly, but it's not 
hard to come up with cases where it would be a lot nicer, like concatenating 
two iterators:

// Before
array_merge(iterator_to_array($iter1), iterator_to_array($iter2))

// Or to generalise to all iterables
array_merge( is_array($iter1) ? $iter1 : iterator_to_array($iter1),
is_array($iter2) ? $iter2 : iterator_to_array($iter2) )

// After (handles both cases)
[ ...$iter1, ...$iter2 ]

Granted, I can't point to a real-life example of that, but it shows that this 
isn't just new syntax for something that's already easy.

Regards,
--
Rowan Collins
[IMSoP]




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to