Reputation: 22176
I have a function that returns a pair of values. At some points in my code, I only need the second value. In Scala, I could do something like this:
[_, secondValue] = functionThatReturnsAPair()
which would discard the first value. Is there such a mechanism in coffeescript, or do I have to declare a variable which is ignored?
Upvotes: 0
Views: 655
Reputation: 434785
You say that you have a function which returns a pair of values. That means that your function actually returns a two element array. So you can say:
a = functionThatReturnsAPair()[1];
The downside of this is that it sort of hides the [1]
off at the right side.
Upvotes: 0
Reputation: 9165
Not exactly the same, but this will do it:
[..., a] = functionThatReturnsAPair()
Upvotes: 2