Usage of _ in scala lambda functions -
can please explain me why can do:
a.mapvalues(_.size) instead of
a.mapvalues(x => x.size) but can't do
a.groupby(_) instead of
a.groupby(x => x)
it isn't easy see here:
a.groupby(_) but it's easier see in this:
a.mkstring("<", _, ">") i'm partially applying method/function. i'm applying parameters (the first , last), , leaving second parameter unapplied, i'm getting new function this:
x => a.mkstring("<", x, ">") the first example special case sole parameter partially applied. when use underscore on expression, however, stands positional parameters in anonymous function.
a.mapvalues(_.size) a.mapvalues(x => x.size) it easy confused, because both result in anonymous function. in fact, there's third underscore used convert method method value (which anonymous function), such as:
a.groupby _
Comments
Post a Comment