- Scala Functional Programming Patterns
- Atul S. Khot
- 186字
- 2021-07-30 09:44:25
Chapter 3. Recursion and Chasing your Own Tail
In the first chapter, we wrote a nested method, groupThem()
, that called itself. In the second chapter, the BST traversal method is similar to the nested method. We saw that the method calls itself to traverse the children. A method calling itself is recursion. In the previous chapter, we also touched upon tail recursion and Scala's @tailrec
annotation.
Let's look at these concepts more closely and see how all these help us write succinct code, and how going recursive promotes immutability. In this chapter, we will first look at recursive structures—a structure is recursive if the shape of the whole recurs in the shape of the parts. We will then look at how Scala's pattern matching helps us to work on the composing parts. Next, we will take a look at a possible problem with very large structures and the mechanism to deal with them—namely tail call optimization (TCO) and @tailrec
annotations. Finally, we will get a handle on persistent data structures and structural sharing to avoid needless copying while preserving immutability.
- Java技術(shù)手冊(cè)(原書第7版)
- Learning Linux Binary Analysis
- SharePoint Development with the SharePoint Framework
- MATLAB 2020從入門到精通
- Python Web數(shù)據(jù)分析可視化:基于Django框架的開發(fā)實(shí)戰(zhàn)
- Mastering Business Intelligence with MicroStrategy
- HTML+CSS+JavaScript網(wǎng)頁設(shè)計(jì)從入門到精通 (清華社"視頻大講堂"大系·網(wǎng)絡(luò)開發(fā)視頻大講堂)
- GameMaker Essentials
- 軟件項(xiàng)目管理實(shí)用教程
- MySQL程序員面試筆試寶典
- Buildbox 2.x Game Development
- IDA Pro權(quán)威指南(第2版)
- Oracle 12c從入門到精通(視頻教學(xué)超值版)
- 計(jì)算語言學(xué)導(dǎo)論
- 交互設(shè)計(jì)師成長(zhǎng)手冊(cè):從零開始學(xué)交互