~~~
object UpperFun extends App{
val l = List(1,2,3,4,5,6,7);
l.map((x:Int)=>x+1);
l.map((x)=>x*2)
l.map(x=>x/2)
//_占位符表示List里面每个元素
val a =l.map(_*2)
println(a)
//filter 拿出所有大于8的
l.map(_*2).filter(_>8).foreach(println)
//1+2 3+3 6+4 两两相加
l.reduce(_+_);
l.reduceLeft(_-_)
l.reduceRight(_-_)
val f = List(List(1,2),List(3,4),List(5,6))
//将二维压扁成一维
f.flatten
//List(List(2, 4), List(6, 8), List(10, 12))
println(f.map(_.map(_*2)))
//List(2, 4, 6, 8, 10, 12)
println(f.flatMap(_.map(_*2)))
}
~~~
![](https://img.kancloud.cn/bb/82/bb82ea695b83edce4949a25f2b453edd_1627x670.png)