-- Mathlib/.lake/packages/lean4/src/lean/Init/Data/Array/Monadic.lean
theorem forIn'_eq_foldlM [Monad m] [LawfulMonad m]
    (l : Array α) (f : (a : α) → a ∈ l → β → m (ForInStep β)) (init : β) :
    forIn' l init f = ForInStep.value <$>
      l.attach.foldlM (fun b ⟨a, m⟩ => match b with
        | .yield b => f a m b
        | .done b => pure (.done b)) (ForInStep.yield init)

Proof state:
case mk
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
init : β
toList✝ : List α
f : (a : α) → a ∈ { toList := toList✝ } → β → m (ForInStep β)
⊢ forIn' { toList := toList✝ } init f =
    ForInStep.value <$>
      foldlM
        (fun b x =>
          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) { toList := toList✝ }.attach

Tactic:
simp [List.forIn'_eq_foldlM, List.foldlM_map]

Result:
case mk
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
init : β
toList✝ : List α
f : (a : α) → a ∈ { toList := toList✝ } → β → m (ForInStep β)
⊢ ForInStep.value <$>
      List.foldlM
        (fun b x =>
          match b with
          | ForInStep.yield b => f x.val ⋯ b
          | ForInStep.done b => pure (ForInStep.done b))
        (ForInStep.yield init) toList✝.attach =
    ForInStep.value <$>
      List.foldlM
        (fun x y =>
          match x with
          | ForInStep.yield b => f y.val ⋯ b
          | ForInStep.done b => pure (ForInStep.done b))
        (ForInStep.yield init) toList✝.attach

Proof state:
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
l : Array α
f : (a : α) → a ∈ l → β → m (ForInStep β)
init : β
⊢ forIn' l init f =
    ForInStep.value <$>
      foldlM
        (fun b x =>
          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) l.attach

Tactic:
cases l

Result:
case mk
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
init : β
toList✝ : List α
f : (a : α) → a ∈ { toList := toList✝ } → β → m (ForInStep β)
⊢ forIn' { toList := toList✝ } init f =
    ForInStep.value <$>
      foldlM
        (fun b x =>
          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) { toList := toList✝ }.attach

Proof state:
case mk
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
init : β
toList✝ : List α
f : (a : α) → a ∈ { toList := toList✝ } → β → m (ForInStep β)
⊢ ForInStep.value <$>
      List.foldlM
        (fun b x =>
          match b with
          | ForInStep.yield b => f x.val ⋯ b
          | ForInStep.done b => pure (ForInStep.done b))
        (ForInStep.yield init) toList✝.attach =
    ForInStep.value <$>
      List.foldlM
        (fun x y =>
          match x with
          | ForInStep.yield b => f y.val ⋯ b
          | ForInStep.done b => pure (ForInStep.done b))
        (ForInStep.yield init) toList✝.attach

Tactic:
congr

Result:
no goals