《Kotlin极简教程》第六章 Kotlin函数式编程(FP)
2023-09-14 09:07:23 时间
Kotlin对函数式编程的实现恰到好处。
正式上架:《Kotlin极简教程》Official on shelves: Kotlin Programming minimalist tutorial
京东JD:https://item.jd.com/12181725.html
天猫Tmall:https://detail.tmall.com/item.htm?id=558540170670
函数指针
/**
* "Callable References" or "Feature Literals", i.e. an ability to pass
* named functions or properties as values. Users often ask
* "I have a foo() function, how do I pass it as an argument?".
* The answer is: "you prefix it with a `::`".
*/
fun main(args: Array<String>) {
val numbers = listOf(1, 2, 3)
println(numbers.filter(::isOdd))
}
fun isOdd(x: Int) =
相关文章
- kotlin延迟属性
- OpenCV + Kotlin 实现 USB 摄像头(相机)实时画面、拍照
- 大人,时代变了!使用 Java 16 或 Kotlin 更好的进行插件或模组开发
- 【Kotlin】Kotlin 单例 ( 懒汉式 与 恶汉式 | Java 单例 | Kotlin 单例 | 对象声明 | 伴生对象 | get 方法 | ? 与 !! 判空 )
- 【Kotlin】Kotlin 语言集合中的高阶函数详解 ( 数据类 data class | maxBy | minBy | filter | map | any | count | find )
- 【JetPack】kotlin-android-extensions 插件 ( 视图绑定简单用法 )
- 【Kotlin】标准库函数 ② ( run 标准库函数 | run 函数传入 Lambda 表达式作为参数 | run 函数传入函数引用作为参数 )
- 【Kotlin】常用的 Kotlin 类 ② ( 枚举类 | 枚举类定义函数 | 密封类 )
- 【Kotlin】函数式编程 ③ ( 早集合与惰性集合 | 惰性集合-序列 | generateSequence 序列创建函数 | 序列代码示例 | take 扩展函数分析 )
- Kotlin极简教程(第一章 Kotlin简介)详解编程语言