June 2017
Beginner
1296 pages
69h 23m
English
A data structure, such as an array or a collection, always represents a finite number of elements—all the elements are stored in memory, and memory is finite. Of course, any stream created from a finite data structure will have a finite number of elements, as has been the case in this chapter’s prior examples.
Lazy evaluation makes it possible to work with infinite streams that represent an unknown, potentially infinite, number of elements. For example, you could define a method nextPrime that produces the next prime number in sequence every time you call it. You could then use this to define an infinite stream that conceptually represents all prime numbers. However, because streams are lazy until you perform a terminal ...