Avoiding unnecessary work
The goal of using lazy evaluation is to avoid unnecessary work. When you're dealing with large collections, there are a lot of values that you don't need. Think about a user interface that displays a list. The source of the list is a collection of values. Since you're only displaying a small portion of this list in the UI, it doesn't make sense to process the whole thing.
Lazy evaluation avoids processing the entire collection by only processing one value at a time and on demand. The idea is that a side-effect is responsible for rendering this list in the UI. The side-effect knows that there is a need to display only 20 items in this list. As this side-effect iterates over a sequence of transformations, it asks the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access