Can anyone please explain me why I can do:
a.mapValues(_.size)
instead of
a.mapValues(x => x.size)
but I can’t do
a.groupBy(_)
instead of a
a.groupBy(x => x)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It isn’t easy to see it here:
But it’s easier to see it in something like this:
I’m partially applying the method/function. I’m applying it to some parameters (the first and last), and leaving the second parameter unapplied, so I’m getting a new function like this:
The first example is just a special case where the sole parameter is partially applied. When you use underscore on an expression, however, it stands for positional parameters in an anonymous function.
It is easy to get confused, because they both result in an anonymous function. In fact, there’s a third underscore that is used to convert a method into a method value (which is also an anonymous function), such as: