I have the following definition:
def f: Option[String] = Some(null)
the following evaluates to None:
for {x:String <- f} yield {
x
}
the following evaluates to Some(null):
for {x <- f} yield {
x
}
the following evaluates to Some(null):
f.map((x:String) => x)
I'm wondering why is there differences between them ?
The desugaring happens in the parser, so
-Xprint:parser
shows the difference:This surprises me because I thought filtering in this way was a feature people wanted but wasn't implemented.
The type pattern is just an instanceof test, so null fails that test.
Without the filter:
In 2.9:
so the filtering feature was added in 2.10.x.
Edit: so actually, this is what you don't get: