Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add reverse spread operator #17

Closed
drupol opened this issue Jan 5, 2023 · 5 comments
Closed

add reverse spread operator #17

drupol opened this issue Jan 5, 2023 · 5 comments

Comments

@drupol
Copy link

drupol commented Jan 5, 2023

Hey hi !

Following our discussion on Mastodon, I'm opening this issue to discuss a new feature.

The idea would be to have a spread operator, but in reverse direction.

Just like we have the spread operator which spread from the left to the right:

$a = range(0, 3);
var_dump(...$a); // Print 0, 1, 2, 3

We could have:

$a = range(0, 3);
var_dump($a...); // Print 3, 2, 1, 0

This reverse operator would spread an iterable from the right to the left.

Let me know what you think about this idea, this is something that would be very cool to have !

Thanks!

@azjezz
Copy link
Member

azjezz commented Jan 5, 2023

I think you mean

$a = range(0, 3);
var_dump($a...); // Print 3, 2, 1, 0

https://3v4l.org/2o0qU

@drupol
Copy link
Author

drupol commented Jan 5, 2023

Yup indeed, I fixed my original message for less confusion.

@azjezz azjezz closed this as completed in 4a781f3 Jan 5, 2023
@azjezz
Copy link
Member

azjezz commented Jan 5, 2023

done ✔️

@azjezz
Copy link
Member

azjezz commented Jan 5, 2023

note: just like the normal spread arguments, reverse spread arguments can't be used in constant expressions.

see: 4a781f3#diff-fcefe4cbaff3c20970310dcdc0805199d85d04b75e5d643d0ce3cf01ced2dd4b

and: 4a781f3#diff-a7eac1cd62ff44bf6e61280cb2cfcee1d21716dd6b017c43394a56c2fc34c60d

@drupol
Copy link
Author

drupol commented Jan 5, 2023

Nice one !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants