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

Pattern Matching but also Entire Result #363

Closed
yfeldblum opened this issue May 6, 2010 · 5 comments
Closed

Pattern Matching but also Entire Result #363

yfeldblum opened this issue May 6, 2010 · 5 comments

Comments

@yfeldblum
Copy link

It would be nice to be able to specify both a name for the whole value and also the names for the parts of the value in the LHS (or in a formal parameter). Here's sample syntax:

myobj: { p1: { a: 1, b: 2 }, p2 : { c: 3, d: 4 } }
myp1@{x, y}: myobj.p1
# myp1 == { a: 1, b: 2 }, x == 1, y == 2

The @ is the character that Haskell uses for this feature. CoffeeScript should choose the syntax most appropriate for and integrated with the rest of CoffeeScript for this particular feature.

@zmthy
Copy link
Collaborator

zmthy commented May 7, 2010

Does this achieve what you're asking for?
{ a: x, b: y }: myp1: myobj.p1
This assigns myobj.p1 to myp1, then deconstructs it into x and y.

@yfeldblum
Copy link
Author

That is nice too. It is not exactly what I had in mind, because it does not operate in a single assignment expression and because it would be difficult to work into the formal parameters.

@jashkenas
Copy link
Owner

I think that Tesco has a solid answer ... that a series of partial matches is a fine way to accomplish this without adding a new symbol to the current syntax. And because pattern-matching-in-parameters isn't happening for now (the sister-issue for this, #362), it's less necessary. Closing as a wontfix.

@mitar
Copy link
Contributor

mitar commented Sep 26, 2014

{ a: x, b: y }: myp1: myobj.p1 does not seem to compile on http://coffeescript.org/ anymore?

@lydell
Copy link
Collaborator

lydell commented Feb 26, 2015

@mitar use { a: x, b: y } = myp1 = myobj.p1 :)

This issue was closed.
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

5 participants