- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 187字
- 2021-07-23 19:05:52
How it works...
As a result, we are going to get the next 20 Fibonacci numbers printed to the console:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]
The additional seed parameter in the generateSequence() provides a starting value. The nextFunction() function is applied to the seed while computing the second value. Later on, it is generating each following element using its preceding value. However, in the case of the Fibonacci sequence, we have two initial values and we need a pair of preceding values in order to compute the next value. For this reason, we wrapped them in Pair type instances. Basically, we are defining a sequence of Pair<Int, Int> type elements, and in each nextFunction() call, we are returning a new pair that holds the values updated accordingly. At the end, we just need to use the map() function to replace each Pair element with the value of its first property. As a result, we are getting an infinite sequence of integer types returning the subsequent Fibonacci numbers.
- Apache Oozie Essentials
- LabVIEW入門與實戰開發100例
- Vue.js 3.0源碼解析(微課視頻版)
- VMware vSphere 6.7虛擬化架構實戰指南
- Access 2010數據庫基礎與應用項目式教程(第3版)
- SQL Server 2012數據庫管理與開發項目教程
- Flux Architecture
- UNIX Linux程序設計教程
- Learning Hadoop 2
- Java圖像處理:基于OpenCV與JVM
- Mastering HTML5 Forms
- Mastering OAuth 2.0
- 軟件測試技術
- H5匠人手冊:霸屏H5實戰解密
- Tkinter GUI Programming by Example