Skip to content

Improving Array destructuring syntax #4092

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

Closed
kiberStender opened this issue Sep 12, 2015 · 1 comment
Closed

Improving Array destructuring syntax #4092

kiberStender opened this issue Sep 12, 2015 · 1 comment

Comments

@kiberStender
Copy link

I think we could improve the syntax adding Scala/Haskell "ignore" syntax in destructuring

[a, _, b, c] = array

would be compiled to

a = array[0], b = array[2], c = array[3]

instead of

a = array[0], _ = array[1], b = array[2], c = array[3]

It does not need to be _, it could be any other character, but it would clean the compiled code and improve memory usage avoiding creating a variable _ with a value we will not use

An better example. RxJs has this "How to use with jQuery"

$("#input").toObservable("keyup")
.map (e) -> e.target.value
.flatMapLatest ajaxCall
.subscribe (data) ->
results = data[1]
$.each results, (_, result) -> //Do Something

instead of results = data[1] we could use [_, results] = data

But the problem is, when we do this the compiler generates this

_ = data[0], results = data[1]

What Im proposing is to generate something like this
results = data[1] and ignore the _ = data[0]

@vendethiel
Copy link
Collaborator

See #3449, #1558 and #3268.

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

No branches or pull requests

2 participants