Strange behavior in for
cycle pattern matching:
scala> val a = Seq(Some(1), None)
a: Seq[Option[Int]] = List(Some(1), None)
scala> for (Some(x) <- a) { println(x) }
1
scala> for (None <- a) { println("none") }
none
none
Why in second example two output 'none'
produced? Maybe this example is synthetic and not practical, but such behavior is not expectable. Is this bug or feature?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…