short way to breakOut to specific collection type?

后端 未结 3 1204
太阳男子
太阳男子 2021-01-12 08:14
scala> val m = Map(1 -> 2)
m: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)

scala>  m.map{case (a, b) => (a+ 1, a+2, a+3)}
res42: scala.colle         


        
3条回答
  •  情歌与酒
    2021-01-12 08:47

    You can make it a bit more concise by letting the type parameters to breakOut be inferred from the return type:

    scala>  m.map{case (a, b) => (a+1, a+2, a+3)}(breakOut) : List[(Int, Int, Int)]
    res3: List[(Int, Int, Int)] = List((2,3,4))
    

提交回复
热议问题