3 ms·
What does the _ do in Scala? I've not used Scala, and it wasn't terribly clear from context unless you mean they use _ exactly as javascript uses => (which wo
by otakucode 10y ago
What does the _ do in Scala? I've not used Scala, and it wasn't terribly clear from context unless you mean they use _ exactly as javascript uses => (which would seem really weird to me so I'm assuming its different, apologies if that is asinine).
- lmm 10y ago"_" is kind of the equivalent of "x => x" (only rather than x it's some temporary generated name that doesn't overlap with anything else). So you'd write "_ * 10" rather than "i => i * 10"
- Nullabillity 10y ago_ is a placeholder for the next lambda argument. So, for example, `x => x.blah()` could be rewritten as `_.blah()`, and `x => blah(x)` could be rewritten as `blah(_)` (or, since we don't need partial application here, simply `blah`). It also works for multiple arguments: `_ * _` is equivalent to `(x, y) => x * y`, which is really `(x, y) => x.*(y)`.