scala map里面怎么传入函数
1个回答
展开全部
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()
}
}
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()
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询