【发布时间】:2018-09-26 01:11:15
【问题描述】:
在 Scala 中我可以做到:
scala> (1 to 5).map( x => if (x % 2 == 0) x else "Not even number" )
res58: scala.collection.immutable.IndexedSeq[Any] = Vector(Not even number, 2, Not even number, 4, Not even number)
但我做不到:
(1 to 5).map( x => (x % 2 == 0) ? x : "Not even number" )
我明白了:
<console>:1: error: identifier expected but string literal found.
有什么想法吗?
【问题讨论】:
标签: scala