-
Notifications
You must be signed in to change notification settings - Fork 2k
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
optional args in destructuring #277
Comments
I brought this up a while back, and it was decided against because the syntax was considered error prone. Perhaps |
Haskell uses the underscore (e.g. below), but of course that's a valid identifier in JavaScript.
|
How about |
If we can settle on a symbol that means "empty" here, I can think of many other situations were that could be used as a kind of placeholder to improve functionalities |
|
I agree it's a great choice. Also, it'd be a lot easier to implement than |
where else do you see opportunities for an empty symbol ? |
It could be a direct reference to |
Well, in parallel with another discussion on
Here, the
Where |
Oh, so the curried |
I always thought it made more sense to use the defer keyword itself to specify this: setTimeout defer, 2000 puts "Two seconds have passed!" |
My take on this is that it's still a little too obscure (rarely-used option to a rarely-used feature), and also that its use-case is mistaken -- if you're destructuring an array and only want one of the values, then:
Isn't the way to write it. You want:
Destructing assignment is more for when you want to pull multiple values out, and in that case, if you're writing a complex pattern match, it's usually instructive to name the variables, even if you're not using them. Of course, you can always use a throwaway variable if you really don't want to name the value, but like named functions by default, having pattern matches be named by default is a nice convention, I think, and makes for code that's easier to read. |
jashkenas: What do you think about the other use cases pointed out? |
Defer is still speculative, but I do think that placeholders are quite helpful for function binding / currying. You don't always want to curry from left-to-right or right-to-left. But in those rare cases, you can always curry by hand, by writing your own function, so it's still by no means essential. |
No idea if this is easy/hard/worth it, but optional args in destructuring arrays might be nice:
The text was updated successfully, but these errors were encountered: