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 ...

Get Learning Java Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.