# RFC proposal - unpack iterator

- Thread: https://externals.io/message/99851
- Original archive: https://news-web.php.net/php.internals/99851
- Started by krukowski.bartlomiej@gmail.com on 2017-07-12T09:22:39+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #99851 — krukowski.bartlomiej@gmail.com — 2017-07-12T09:22:39+00:00

URL: https://externals.io/message/99851#99851

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 — Marco Pivetta — 2017-07-12T12:06:03+00:00

URL: https://externals.io/message/99851#99852 · In reply to: #99851

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 — krukowski.bartlomiej@gmail.com — 2017-07-12T12:09:32+00:00

URL: https://externals.io/message/99851#99853 · In reply to: #99852

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:
>
> > […]
>
> 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 — Marco Pivetta — 2017-07-12T12:12:28+00:00

URL: https://externals.io/message/99851#99854 · In reply to: #99853

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>:
>
> > […]
>
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 — krukowski.bartlomiej@gmail.com — 2017-07-12T12:19:53+00:00

URL: https://externals.io/message/99851#99855 · In reply to: #99854

>
> 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:
>
> > […]
> 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/
