- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 61字
- 2021-07-23 19:05:52
How to do it...
- Declare a function called fibonacci() and use the generateSequence() function to define a formula for the next elements of the sequence:
fun fibonacci(): Sequence<Int> {
return generateSequence(Pair(0, 1)) { Pair(it.second, it.first + it.second) }
.map { it.first }
}
- Use the fibonacci() function to print the next Fibonacci numbers to the console:
println(fibonacci().take(20).toList())
推薦閱讀
- jQuery Mobile Web Development Essentials(Third Edition)
- Getting Started with React
- MySQL數據庫應用與管理 第2版
- Mastering SVG
- PHP 7底層設計與源碼實現
- Mastering Rust
- Oracle GoldenGate 12c Implementer's Guide
- Geospatial Development By Example with Python
- jQuery技術內幕:深入解析jQuery架構設計與實現原理
- C# 7.0本質論
- ASP.NET Core and Angular 2
- Elasticsearch搜索引擎構建入門與實戰
- 自己動手構建編程語言:如何設計編譯器、解釋器和DSL
- Clojure編程樂趣
- React.js實戰