高阶函数

2018-12-01  本文已影响0人  zlzxm

1.forEach :类型 :( (Int) -> Unit): Unit 

2.map:类型:((Int) ->R): List<R>  :在迭代每一个元素时对元素进行变化 然后添加到新的 数组中 返回新数组

3.flatMap:类型(transform: (Int) -> Iterable<R>): List<R>: 变换同时打平 其中的集合

4.reduce:类型 ((acc: Int, Int) -> Int): Int  : ps(for (indexin 1..lastIndex) {)

accumulator = operation(accumulator,this[index])

} ):  对 相邻两个数的循环操作。 可用于对 所有元素的 基本运算

5.fold:类型(initial:R, operation: (acc:R, Int) ->R):R ps(for (elementin this) accumulator = operation(accumulator, element)): 和 reduce相同,不同的是 reduce初始值为集合的第一个元素,fold 的初始值用户决定 返回值也由用户决定

6.filter:类型:((predicate: (Int) -> Boolean): List<Int>)

7.let

8.apply

8.with

9.use

看源码

上一篇下一篇

猜你喜欢

热点阅读