flatmap详解
来源:互联网 发布:制作桌面的软件 编辑:程序博客网 时间:2024/06/05 15:24
flatMap
flatMap
是一种常用的组合子,结合映射[mapping]和扁平化[flattening]。 flatMap需要一个处理嵌套列表的函数,然后将结果串连起来。
scala> val nestedNumbers = List(List(1, 2), List(3, 4))nestedNumbers: List[List[Int]] = List(List(1, 2), List(3, 4))scala> nestedNumbers.flatMap(x => x.map(_ * 2))res0: List[Int] = List(2, 4, 6, 8)
可以把它看做是“先映射后扁平化”的快捷操作:
scala> nestedNumbers.map((x: List[Int]) => x.map(_ * 2)).flattenres1: List[Int] = List(2, 4, 6, 8)
这个例子先调用map,然后可以马上调用flatten,这就是“组合子”的特征,也是这些函数的本质
0 0
- flatmap详解
- RxJava flatMap操作符用法详解
- Spark RDD中Transformation的map、flatMap、mapPartitions、glom详解
- RxJava(三) flatMap操作符用法详解
- RxJava flatmap
- spark flatmap
- spark flatmap
- Java flatMap
- flatMap Map
- Spark API 详解/大白话解释 之 map、mapPartitions、mapValues、mapWith、flatMap、flatMapWith、flatMapValues
- Spark API 详解/大白话解释 之 map、mapPartitions、mapValues、mapWith、flatMap、flatMapWith、flatMapValues
- spark val b = a.flatMap(x => 1 to x)详解
- Monads之flatMap,unit
- map与flatmap区别
- Spark map flatMap
- Swift FlatMap or Map
- swift - map() 与flatMap()
- RxJava 操作符flatmap
- 点击回退键时出现连续返回的情况
- 代理反向传值
- C++中引用和指针的区别
- 深入浅出谈计算机语言的发展
- hdu 5330 Route Statistics(状压dp)
- flatmap详解
- C语言运算符
- list列表获取当前行数据【WeX5】
- UC应用中心数据 HTML5应用添加近亿次
- nyoj 苹果 289 (简单01背包)
- 写让别人能读懂的代码
- 1009. Product of Polynomials (25)
- NSString 对象的创建
- 小黑升级SSD实录