Lemmas about Vector.forIn' and Vector.forIn. #
Monadic operations #
mapM #
foldlM and foldrM #
forM #
forIn' #
theorem Vector.forIn'_congr {m : Type u_1 → Type u_2} {α : Type u_3} {n : Nat} {β : Type u_1} [Monad m] {xs ys : Vector α n} (w : xs = ys) {b b' : β} (hb : b = b') {f : (a' : α) → a' ∈ xs → β → m (ForInStep β)} {g : (a' : α) → a' ∈ ys → β → m (ForInStep β)} (h : ∀ (a : α) (m_1 : a ∈ ys) (b : β), f a ⋯ b = g a m_1 b) :
theorem Vector.forIn'_eq_foldlM {m : Type u_1 → Type u_2} {α : Type u_3} {n : Nat} {β : Type u_1} [Monad m] [LawfulMonad m] {xs : Vector α n} (f : (a : α) → a ∈ xs → β → m (ForInStep β)) (init : β) :
forIn' xs init f = ForInStep.value <$> foldlM
(fun (b : ForInStep β) (x : { x : α // x ∈ xs }) =>
match x with
| ⟨a, m_1⟩ =>
match b with
| ForInStep.yield b => f a m_1 b
| ForInStep.done b => pure (ForInStep.done b))
(ForInStep.yield init) xs.attach
We can express a for loop over a vector as a fold,
in which whenever we reach .done b we keep that value through the rest of the fold.
@[simp]
theorem Vector.forIn'_yield_eq_foldlM {m : Type u_1 → Type u_2} {α : Type u_3} {n : Nat} {β γ : Type u_1} [Monad m] [LawfulMonad m] {xs : Vector α n} (f : (a : α) → a ∈ xs → β → m γ) (g : (a : α) → a ∈ xs → β → γ → β) (init : β) :
We can express a for loop over a vector which always yields as a fold.
@[simp]
theorem Vector.forIn'_pure_yield_eq_foldl {m : Type u_1 → Type u_2} {α : Type u_3} {n : Nat} {β : Type u_1} [Monad m] [LawfulMonad m] {xs : Vector α n} (f : (a : α) → a ∈ xs → β → β) (init : β) :
theorem Vector.forIn_eq_foldlM {m : Type u_1 → Type u_2} {α : Type u_3} {n : Nat} {β : Type u_1} [Monad m] [LawfulMonad m] {xs : Vector α n} (f : α → β → m (ForInStep β)) (init : β) :
forIn xs init f = ForInStep.value <$> foldlM
(fun (b : ForInStep β) (a : α) =>
match b with
| ForInStep.yield b => f a b
| ForInStep.done b => pure (ForInStep.done b))
(ForInStep.yield init) xs
We can express a for loop over a vector as a fold,
in which whenever we reach .done b we keep that value through the rest of the fold.
@[simp]
theorem Vector.forIn_yield_eq_foldlM {m : Type u_1 → Type u_2} {α : Type u_3} {n : Nat} {β γ : Type u_1} [Monad m] [LawfulMonad m] {xs : Vector α n} (f : α → β → m γ) (g : α → β → γ → β) (init : β) :
We can express a for loop over a vector which always yields as a fold.
@[simp]
theorem Vector.forIn_pure_yield_eq_foldl {m : Type u_1 → Type u_2} {α : Type u_3} {n : Nat} {β : Type u_1} [Monad m] [LawfulMonad m] {xs : Vector α n} (f : α → β → β) (init : β) :