LazyList: A Lazy Version of List
In this lesson, you will be introduced to LazyLists; the lazy version of Lists.
We'll cover the following
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.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy