Documentation

Mathlib.Data.LazyList

Lazy lists #

The type LazyList α is a lazy list with elements of type α. In the VM, these are potentially infinite lists where all elements after the first are computed on-demand. (This is only useful for execution in the VM, logically we can prove that LazyList α is isomorphic to List α.)

inductive LazyList (α : Type u) :

Lazy list. All elements (except the first) are computed lazily.

Instances For
    Equations
    • LazyList.instInhabitedLazyList = { default := LazyList.nil }
    def LazyList.singleton {α : Type u} :
    α → LazyList α

    The singleton lazy list.

    Equations
    Instances For
      def LazyList.ofList {α : Type u} :
      List α → LazyList α

      Constructs a lazy list from a list.

      Equations
      Instances For
        def LazyList.toList {α : Type u} :
        LazyList α → List α

        Converts a lazy list to a list. If the lazy list is infinite, then this function does not terminate.

        Equations
        Instances For
          def LazyList.headI {α : Type u} [Inhabited α] :
          LazyList α → α

          Returns the first element of the lazy list, or default if the lazy list is empty.

          Equations
          Instances For
            def LazyList.tail {α : Type u} :
            LazyList α → LazyList α

            Removes the first element of the lazy list.

            Equations
            Instances For
              def LazyList.append {α : Type u} :
              LazyList α → Thunk (LazyList α) → LazyList α

              Appends two lazy lists.

              Equations
              Instances For
                def LazyList.map {α : Type u} {β : Type v} (f : α → β) :
                LazyList α → LazyList β

                Maps a function over a lazy list.

                Equations
                Instances For
                  def LazyList.map₂ {α : Type u} {β : Type v} {δ : Type w} (f : α → β → δ) :
                  LazyList α → LazyList β → LazyList δ

                  Maps a binary function over two lazy list. Like LazyList.zip, the result is only as long as the smaller input.

                  Equations
                  Instances For
                    def LazyList.zip {α : Type u} {β : Type v} :
                    LazyList α → LazyList β → LazyList (α × β)

                    Zips two lazy lists.

                    Equations
                    Instances For
                      def LazyList.join {α : Type u} :

                      The monadic join operation for lazy lists.

                      Equations
                      Instances For
                        def LazyList.for {α : Type u} {β : Type v} (l : LazyList α) (f : α → β) :

                        Maps a function over a lazy list. Same as LazyList.map, but with swapped arguments.

                        Equations
                        Instances For
                          def LazyList.approx {α : Type u} :
                          Nat → LazyList α → List α

                          The list containing the first n elements of a lazy list.

                          Equations
                          Instances For
                            def LazyList.filter {α : Type u} (p : α → Prop) [DecidablePred p] :
                            LazyList α → LazyList α

                            The lazy list of all elements satisfying the predicate. If the lazy list is infinite and none of the elements satisfy the predicate, then this function will not terminate.

                            Equations
                            Instances For
                              def LazyList.nth {α : Type u} :
                              LazyList α → Nat → Option α

                              The nth element of a lazy list as an option (like List.get?).

                              Equations
                              Instances For
                                unsafe def LazyList.iterates {α : Type u} (f : α → α) :
                                α → LazyList α

                                The infinite lazy list [x, f x, f (f x), ...] of iterates of a function. This definition is meta because it creates an infinite list.

                                Equations
                                Instances For
                                  unsafe def LazyList.iota (i : Nat) :

                                  The infinite lazy list [i, i+1, i+2, ...]

                                  Equations
                                  Instances For