docs.scala-lang
docs.scala-lang copied to clipboard
Placeholder FAQ claim overreaches
Reproduction steps
scala 2.13.8> List(42).flatMap(List(_ + 1))
^
error: missing parameter type for expanded function ((<x$1: error>) => x$1.$plus(1))
scala 2.13.8> List(42).flatMap(List apply _ + 1)
val res1: List[Int] = List(43)
Problem
The FAQ claims the function can't be written with placeholder syntax.
~I wouldn't call that "placeholder syntax", just because it's underscore? Looks like explicit eta-expansion syntax to me, and that's something else.~
The actual FAQ wording is:
The latter function cannot be written using the _ syntax
I wouldn't mind changing the wording a bit, but I don't think we should remove the claim altogether given that this List apply _ business is corner-case style weirdness that would never have occurred to me to even try and certainly would never occur to a language newcomer.
It's place holder syntax, where it's translated to x => expr(x).
I remember when I first saw someone point out how infix enables extra underscore powers. It seems magical at first, but is just ordinary syntax. Precedence rules matter in this example.
It's place holder syntax, where it's translated
Oops, I thought I'd removed that sentence, after Dale set me straight. I've strikethroughed it.
Taxi drivers are on strikethru, so let me know if you need a ride from the airport.
FAQ is for brevity. That's why we call it FAQ for short.