Lazy and eager evaluation
There are three terms dealing with this topic: lazy loading, lazy evaluation, and eager evaluation. They are all present in most functional programming languages. These terms are defined as follows:
Lazy loading: Delaying an expensive loading operation until needed.
Lazy evaluation: Refers to the delaying of the evaluation of an operation until it is needed. Lazy evaluation support infinite streams.
Eager evaluation: An operation is executed as soon as it is encountered.
We will discuss lazy and eager evaluation in this section. Lazy loading can occur when a line of a file is not read until it needs to be processed. This can occur in a stream when a line is read depending on the operations performed. Streams are sometimes called lazy sequences because they are often evaluated in a lazy manner.
The following demonstrates lazy evaluation. A part of this example first appeared in Chapter 1, Getting Started with Functional Programming. Here, we clearly show that the stream...