RFC proposal - unpack iterator

  99851
July 12, 2017 09:22 krukowski.bartlomiej@gmail.com (=?UTF-8?Q?Bart=C5=82omiej_Krukowski?=)
Hello,
From PHP 5.6 we have possibility to add variadic functions and unpacking
arrays via *...*
Would be nice to extend responsibility of *...*. Sometimes in code I can
find lines similar to the following:

$result = array_merge(['some value'], ['some other value'], $array);


I would like to shorten this line to the following:

$result = ['some value', ['some other value'], ...$array];


And even allow to unpack more than one array:

$result = ['some value', ['some other value'], ...$array, ...$secondArray];


Using new operator we can produce shorter and more clearable code. I would
like to create RFC for my proposal. If you think idea can be useful, please
give me an access for creating RFC.

Best regards
  99852
July 12, 2017 12:06 ocramius@gmail.com (Marco Pivetta)
On Wed, Jul 12, 2017 at 11:22 AM, Bartłomiej Krukowski <
krukowski.bartlomiej@gmail.com> wrote:

> Hello, > From PHP 5.6 we have possibility to add variadic functions and unpacking > arrays via *...* > Would be nice to extend responsibility of *...*. Sometimes in code I can > find lines similar to the following: > > $result = array_merge(['some value'], ['some other value'], $array); > > > I would like to shorten this line to the following: > > $result = ['some value', ['some other value'], ...$array]; > > > And even allow to unpack more than one array: > > $result = ['some value', ['some other value'], ...$array, ...$secondArray]; > > > Using new operator we can produce shorter and more clearable code. I would > like to create RFC for my proposal. If you think idea can be useful, please > give me an access for creating RFC. > > Best regards >
Would this allow operations such as the following one? $a = [0]; $b = [1]; $otherArrays = [[2,3], [4,5]]; $mergeAll = [...$a, ...$b, ...[...$otherArrays]]; // [0, 1, 2, 3, 4, 5] Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/
  99853
July 12, 2017 12:09 krukowski.bartlomiej@gmail.com (=?UTF-8?Q?Bart=C5=82omiej_Krukowski?=)
Hello,

Yes, this is exactly what I would like to achieve.

Best regards

2017-07-12 14:06 GMT+02:00 Marco Pivetta <ocramius@gmail.com>:

> On Wed, Jul 12, 2017 at 11:22 AM, Bartłomiej Krukowski < > krukowski.bartlomiej@gmail.com> wrote: > >> Hello, >> From PHP 5.6 we have possibility to add variadic functions and unpacking >> arrays via *...* >> Would be nice to extend responsibility of *...*. Sometimes in code I can >> find lines similar to the following: >> >> $result = array_merge(['some value'], ['some other value'], $array); >> >> >> I would like to shorten this line to the following: >> >> $result = ['some value', ['some other value'], ...$array]; >> >> >> And even allow to unpack more than one array: >> >> $result = ['some value', ['some other value'], ...$array, >> ...$secondArray]; >> >> >> Using new operator we can produce shorter and more clearable code. I would >> like to create RFC for my proposal. If you think idea can be useful, >> please >> give me an access for creating RFC. >> >> Best regards >> > > Would this allow operations such as the following one? > > $a = [0]; > $b = [1]; > $otherArrays = [[2,3], [4,5]]; > $mergeAll = [...$a, ...$b, ...[...$otherArrays]]; // [0, 1, 2, 3, 4, 5] > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > > >
  99854
July 12, 2017 12:12 ocramius@gmail.com (Marco Pivetta)
On Wed, Jul 12, 2017 at 2:09 PM, Bartłomiej Krukowski <
krukowski.bartlomiej@gmail.com> wrote:

> Hello, > > Yes, this is exactly what I would like to achieve. > > Best regards > > 2017-07-12 14:06 GMT+02:00 Marco Pivetta <ocramius@gmail.com>: > >> On Wed, Jul 12, 2017 at 11:22 AM, Bartłomiej Krukowski < >> krukowski.bartlomiej@gmail.com> wrote: >> >>> Hello, >>> From PHP 5.6 we have possibility to add variadic functions and unpacking >>> arrays via *...* >>> Would be nice to extend responsibility of *...*. Sometimes in code I can >>> find lines similar to the following: >>> >>> $result = array_merge(['some value'], ['some other value'], $array); >>> >>> >>> I would like to shorten this line to the following: >>> >>> $result = ['some value', ['some other value'], ...$array]; >>> >>> >>> And even allow to unpack more than one array: >>> >>> $result = ['some value', ['some other value'], ...$array, >>> ...$secondArray]; >>> >>> >>> Using new operator we can produce shorter and more clearable code. I >>> would >>> like to create RFC for my proposal. If you think idea can be useful, >>> please >>> give me an access for creating RFC. >>> >>> Best regards >>> >> >> Would this allow operations such as the following one? >> >> $a = [0]; >> $b = [1]; >> $otherArrays = [[2,3], [4,5]]; >> $mergeAll = [...$a, ...$b, ...[...$otherArrays]]; // [0, 1, 2, 3, 4, 5] >> >> Marco Pivetta >> >> http://twitter.com/Ocramius >> >> http://ocramius.github.com/ >> >> >> > TBH, I'd like to have a functional approach to this, so that I can use
functional composition instead of operators (`array_map('...', $values))`). Still, the addition is very nice and complimentary with the existing splat/variadic argument stuff :D Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/
  99855
July 12, 2017 12:19 krukowski.bartlomiej@gmail.com (=?UTF-8?Q?Bart=C5=82omiej_Krukowski?=)
> > so that I can use functional composition instead of operators > (`array_map('...', $values))`).
I think I do not understand. Still, the addition is very nice and complimentary with the existing
> splat/variadic argument stuff :D
So can I create RFC? :) 2017-07-12 14:12 GMT+02:00 Marco Pivetta <ocramius@gmail.com>:
> On Wed, Jul 12, 2017 at 2:09 PM, Bartłomiej Krukowski < > krukowski.bartlomiej@gmail.com> wrote: > >> Hello, >> >> Yes, this is exactly what I would like to achieve. >> >> Best regards >> >> 2017-07-12 14:06 GMT+02:00 Marco Pivetta <ocramius@gmail.com>: >> >>> On Wed, Jul 12, 2017 at 11:22 AM, Bartłomiej Krukowski < >>> krukowski.bartlomiej@gmail.com> wrote: >>> >>>> Hello, >>>> From PHP 5.6 we have possibility to add variadic functions and unpacking >>>> arrays via *...* >>>> Would be nice to extend responsibility of *...*. Sometimes in code I can >>>> find lines similar to the following: >>>> >>>> $result = array_merge(['some value'], ['some other value'], $array); >>>> >>>> >>>> I would like to shorten this line to the following: >>>> >>>> $result = ['some value', ['some other value'], ...$array]; >>>> >>>> >>>> And even allow to unpack more than one array: >>>> >>>> $result = ['some value', ['some other value'], ...$array, >>>> ...$secondArray]; >>>> >>>> >>>> Using new operator we can produce shorter and more clearable code. I >>>> would >>>> like to create RFC for my proposal. If you think idea can be useful, >>>> please >>>> give me an access for creating RFC. >>>> >>>> Best regards >>>> >>> >>> Would this allow operations such as the following one? >>> >>> $a = [0]; >>> $b = [1]; >>> $otherArrays = [[2,3], [4,5]]; >>> $mergeAll = [...$a, ...$b, ...[...$otherArrays]]; // [0, 1, 2, 3, 4, 5] >>> >>> Marco Pivetta >>> >>> http://twitter.com/Ocramius >>> >>> http://ocramius.github.com/ >>> >>> >>> >> > TBH, I'd like to have a functional approach to this, so that I can use > functional composition instead of operators (`array_map('...', $values))`). > > Still, the addition is very nice and complimentary with the existing > splat/variadic argument stuff :D > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > >