File: .lake/packages/batteries/Batteries/Data/LazyList.lean

full_name: LazyList.nil
code: /-- Lazy list.
All elements (except the first) are computed lazily.
-/
@[deprecated "Consider using `MLList`." (since := "2024-07-15")]
inductive LazyList (α : Type u) : Type u
  /-- The empty lazy list. -/
  | nil : LazyList α
  /-- Construct a lazy list from an element and a tail inside a thunk. -/
  | cons (hd : α) (tl : Thunk <| LazyList α) : LazyList α
goal: LazyList α

full_name: LazyList.cons
code: /-- Lazy list.
All elements (except the first) are computed lazily.
-/
@[deprecated "Consider using `MLList`." (since := "2024-07-15")]
inductive LazyList (α : Type u) : Type u
  /-- The empty lazy list. -/
  | nil : LazyList α
  /-- Construct a lazy list from an element and a tail inside a thunk. -/
  | cons (hd : α) (tl : Thunk <| LazyList α) : LazyList α
goal: LazyList α

full_name: LazyList
code: /-- Lazy list.
All elements (except the first) are computed lazily.
-/
@[deprecated "Consider using `MLList`." (since := "2024-07-15")]
inductive LazyList (α : Type u) : Type u
  /-- The empty lazy list. -/
  | nil : LazyList α
  /-- Construct a lazy list from an element and a tail inside a thunk. -/
  | cons (hd : α) (tl : Thunk <| LazyList α) : LazyList α
goal: Type u

full_name: LazyList.instInhabited
code: instance : Inhabited (LazyList α) 
goal: Inhabited (LazyList α)

full_name: LazyList.singleton
code: /-- The singleton lazy list.  -/
def singleton : α → LazyList α
  
goal: α → LazyList α

full_name: LazyList.ofList
code: /-- Constructs a lazy list from a list. -/
def ofList : List α → LazyList α
  
goal: List α → LazyList α

full_name: LazyList.toList
code: /-- Converts a lazy list to a list.
If the lazy list is infinite,
then this function does not terminate.
-/
def toList : LazyList α → List α
  
goal: LazyList α → List α

full_name: LazyList.headI
code: /-- Returns the first element of the lazy list,
or `default` if the lazy list is empty.
-/
def headI [Inhabited α] : LazyList α → α
  
goal: LazyList α → α

full_name: LazyList.tail
code: /-- Removes the first element of the lazy list.
-/
def tail : LazyList α → LazyList α
  
goal: LazyList α → LazyList α

full_name: LazyList.append
code: /-- Appends two lazy lists.  -/
def append : LazyList α → Thunk (LazyList α) → LazyList α
  
goal: LazyList α → Thunk (LazyList α) → LazyList α

full_name: LazyList.map
code: /-- Maps a function over a lazy list. -/
def map (f : α → β) : LazyList α → LazyList β
  
goal: LazyList α → LazyList β

full_name: LazyList.map₂
code: /-- Maps a binary function over two lazy list.
Like `LazyList.zip`, the result is only as long as the smaller input.
-/
def map₂ (f : α → β → δ) : LazyList α → LazyList β → LazyList δ
  
goal: LazyList α → LazyList β → LazyList δ

full_name: LazyList.zip
code: /-- Zips two lazy lists. -/
def zip : LazyList α → LazyList β → LazyList (α × β) 
goal: LazyList α → LazyList β → LazyList (α × β)

full_name: LazyList.join
code: /-- The monadic join operation for lazy lists. -/
def join : LazyList (LazyList α) → LazyList α
  
goal: LazyList (LazyList α) → LazyList α

full_name: LazyList.take
code: /-- The list containing the first `n` elements of a lazy list.  -/
def take : Nat → LazyList α → List α
  
goal: Nat → LazyList α → List α

full_name: LazyList.filter
code: /-- 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.
-/
def filter (p : α → Prop) [DecidablePred p] : LazyList α → LazyList α
  
goal: LazyList α → LazyList α

full_name: LazyList.get?
code: /-- The nth element of a lazy list as an option (like `List.get?`). -/
def get? : LazyList α → Nat → Option α
  
goal: LazyList α → Nat → Option α

full_name: LazyList.iterates
code: /-- The infinite lazy list `[x, f x, f (f x), ...]` of iterates of a function.
This definition is partial because it creates an infinite list.
-/
partial def iterates (f : α → α) : α → LazyList α
  
goal: α → LazyList α

full_name: LazyList.iota
code: /-- The infinite lazy list `[i, i+1, i+2, ...]` -/
partial def iota (i : Nat) : LazyList Nat 
goal: LazyList Nat

full_name: LazyList.decidableEq
code: instance decidableEq {α : Type u} [DecidableEq α] : DecidableEq (LazyList α)
  
goal: DecidableEq (LazyList α)

full_name: LazyList.traverse
code: /-- Traversal of lazy lists using an applicative effect. -/
protected def traverse {m : Type u → Type u} [Applicative m] {α β : Type u} (f : α → m β) :
    LazyList α → m (LazyList β)
  
goal: LazyList α → m (LazyList β)

full_name: LazyList.init
code: /-- `init xs`, if `xs` non-empty, drops the last element of the list.
Otherwise, return the empty list. -/
def init {α} : LazyList α → LazyList α
  
goal: LazyList α → LazyList α

full_name: LazyList.find
code: /-- Return the first object contained in the list that satisfies
predicate `p` -/
def find {α} (p : α → Prop) [DecidablePred p] : LazyList α → Option α
  
goal: LazyList α → Option α

full_name: LazyList.interleave
code: /-- `interleave xs ys` creates a list where elements of `xs` and `ys` alternate. -/
def interleave {α} : LazyList α → LazyList α → LazyList α
  
goal: LazyList α → LazyList α → LazyList α

full_name: LazyList.interleaveAll
code: /-- `interleaveAll (xs::ys::zs::xss)` creates a list where elements of `xs`, `ys`
and `zs` and the rest alternate. Every other element of the resulting list is taken from
`xs`, every fourth is taken from `ys`, every eighth is taken from `zs` and so on. -/
def interleaveAll {α} : List (LazyList α) → LazyList α
  
goal: List (LazyList α) → LazyList α

full_name: LazyList.bind
code: /-- Monadic bind operation for `LazyList`. -/
protected def bind {α β} : LazyList α → (α → LazyList β) → LazyList β
  
goal: LazyList α → (α → LazyList β) → LazyList β

full_name: LazyList.reverse
code: /-- Reverse the order of a `LazyList`.
It is done by converting to a `List` first because reversal involves evaluating all
the list and if the list is all evaluated, `List` is a better representation for
it than a series of thunks. -/
def reverse {α} (xs : LazyList α) : LazyList α 
goal: LazyList α

full_name: LazyList.instMonad
code: instance : Monad LazyList 
goal: Monad LazyList

full_name: LazyList.append_nil
code: theorem append_nil {α} (xs : LazyList α) : xs.append (Thunk.pure LazyList.nil) = xs 
goal: xs.append (Thunk.pure LazyList.nil) = xs

full_name: LazyList.append_assoc
code: theorem append_assoc {α} (xs ys zs : LazyList α) :
    (xs.append ys).append zs = xs.append (ys.append zs) 
goal: (xs.append { fn := fun x => ys }).append { fn := fun x => zs } =
  xs.append { fn := fun x => ys.append { fn := fun x => zs } }

full_name: LazyList.append_bind
code: theorem append_bind {α β} (xs : LazyList α) (ys : Thunk (LazyList α)) (f : α → LazyList β) :
    (xs.append ys).bind f = (xs.bind f).append (ys.get.bind f) 
goal: (xs.append ys).bind f = (xs.bind f).append { fn := fun x => ys.get.bind f }

full_name: LazyList.mfirst
code: /-- Try applying function `f` to every element of a `LazyList` and
return the result of the first attempt that succeeds. -/
def mfirst {m} [Alternative m] {α β} (f : α → m β) : LazyList α → m β
  
goal: LazyList α → m β

full_name: LazyList.Mem
code: /-- Membership in lazy lists -/
protected def Mem {α} (x : α) : LazyList α → Prop
  
goal: LazyList α → Prop

full_name: LazyList.instMembership
code: instance {α} : Membership α (LazyList α) 
goal: Membership α (LazyList α)

full_name: LazyList.Mem.decidable
code: instance Mem.decidable {α} [DecidableEq α] (x : α) : ∀ xs : LazyList α, Decidable (x ∈ xs)
  
goal: Decidable (x ∈ xs)

full_name: LazyList.mem_nil
code: @[simp]
theorem mem_nil {α} (x : α) : x ∈ @LazyList.nil α ↔ False 
goal: x ∈ LazyList.nil ↔ False

full_name: LazyList.mem_cons
code: @[simp]
theorem mem_cons {α} (x y : α) (ys : Thunk (LazyList α)) :
    x ∈ @LazyList.cons α y ys ↔ x = y ∨ x ∈ ys.get 
goal: x ∈ LazyList.cons y ys ↔ x = y ∨ x ∈ ys.get

full_name: LazyList.forall_mem_cons
code: theorem forall_mem_cons {α} {p : α → Prop} {a : α} {l : Thunk (LazyList α)} :
    (∀ x ∈ @LazyList.cons _ a l, p x) ↔ p a ∧ ∀ x ∈ l.get, p x 
goal: (∀ (x : α), x ∈ LazyList.cons a l → p x) ↔ p a ∧ ∀ (x : α), x ∈ l.get → p x

full_name: LazyList.pmap
code: /-- Partial map. If `f : ∀ a, p a → β` is a partial function defined on
  `a : α` satisfying `p`, then `pmap f l h` is essentially the same as `map f l`
  but is defined only when all members of `l` satisfy `p`, using the proof
  to apply `f`. -/
@[simp]
def pmap {α β} {p : α → Prop} (f : ∀ a, p a → β) : ∀ l : LazyList α, (∀ a ∈ l, p a) → LazyList β
  
goal: (∀ (a : α), a ∈ l → p a) → LazyList β

full_name: LazyList.attach
code: /-- "Attach" the proof that the elements of `l` are in `l` to produce a new `LazyList`
  with the same elements but in the type `{x // x ∈ l}`. -/
def attach {α} (l : LazyList α) : LazyList { x // x ∈ l } 
goal: LazyList { x // x ∈ l }

full_name: LazyList.instRepr
code: instance {α} [Repr α] : Repr (LazyList α) 
goal: Repr (LazyList α)