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

Destructuring assignments? #63

Open
00dani opened this issue Aug 24, 2015 · 3 comments
Open

Destructuring assignments? #63

00dani opened this issue Aug 24, 2015 · 3 comments

Comments

@00dani
Copy link

00dani commented Aug 24, 2015

There doesn't appear to be any support for destructuring objects or arrays during assignment.

I tried the following code:

{count by, is equal} = require 'underscore'
(s1) is permutation of (s2) =
    (count by (s1)) is equal (count by (s2))

expecting it to produce JS equivalent to:

var temp = require('underscore');
var countBy = temp.countBy, isEqual = temp.isEqual;
var isPermutationOf = function(s1, s2) {
    return isEqual(countBy(s1), countBy(s2));
};

but no dice. It looks like currently this is a syntax error, so adding support shouldn't (?) break existing code.

More generally, destructuring assignment should probably work like:

[x, y] = [1, 2] // x = 1, y = 2
[x, y, ..., z] = [1, 2, 3, 4, 5] // x = 1, y = [2, 3, 4], z = 5
{a, b} = {a = 1, b = 2} // a = 1, b = 2
{x = a, y = b} = {x = 5, y = 7} // a = 5, b = 7

It'd also make sense to support the syntax in function arguments:

map (f) over ([head, tail, ...]) =
  f (head).concat (map (f) over (tail))
  // obviously needs a check for the base case but you get the idea

Thoughts?

@joshski
Copy link
Member

joshski commented Aug 24, 2015

+1

@joshski
Copy link
Member

joshski commented Aug 24, 2015

As in, I'd like to see destructuring assignments 😀

@sphvn
Copy link

sphvn commented Aug 26, 2015

Would very much like destructuring assignments also.

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

3 participants