We discussed recursion, which help us to iterate sequences easily, in the previous chapter. Furthermore, we need to discuss about optimizing code since it is an essential technique if we want to develop a good program. In a functional approach, we can use laziness and caching techniques to make our code efficient so that it will run faster. By discussing laziness and caching techniques, we will be able to develop efficient code. To learn more about laziness and caching techniques, in this chapter, we will discuss the following topics:
Implementing laziness in our code: lazy enumeration, lazy evaluation, nonstrict evaluation, and lazy initialization
The benefit of being lazy
Caching expensive resources using precomputation and memoization