Introduction
Creating a LazyList
Lazy Computation
Streams
Introduction
A LazyList is an immutable sequence type collection very similar to Lists. What makes a LazyList lazy is that it only computes required elements, allowing it to be infinitely long. Other than this difference, LazyLists have the same performance characteristics as Lists, hence, to avoid repetition, we won’t discuss them here.
Creating a LazyList
Similar to the :: method used for creating Lists, LazyLists are created with the #:: method. The first element is the head while all other elements are collectively known as the tail. We use LazyList.empty to end a LazyList, which is equivalent to the Nil used for ending a List.