scala map里面怎么傳入函數(shù)
scala map里面怎么傳入函數(shù)
慕婉清6462132
2019-05-31 03:02:31
TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊
def flatMap1(): Unit = {
val li = List(1,2,3)
val res = li.flatMap(x => x match {
case 3 => List('a','b')
case _ => List(x*2)
})
println(res)
}
def map1(): Unit = {
val li = List(1,2,3)
val res = li.map(x => x match {
case 3 => List('a','b')
case _ => x*2
})
println(res)
}
def main(args: Array[String]): Unit = {
flatMap1()
map1()
}
}
舉報(bào)