-- Mathlib/.lake/packages/lean4/src/lean/Init/Internal/Order/Lemmas.lean
theorem monotone_findSomeM?
    (f : γ → α → m (Option β)) (xs : Array α) (hmono : monotone f) :
    monotone (fun x => xs.findSomeM? (f x))

Proof state:
case hmono₁
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
⊢ monotone fun x =>
    forIn xs ⟨none, PUnit.unit⟩ fun a r =>
      let r := r.snd;
      do
      let __do_lift ← f x a
      match __do_lift with
        | some b => pure (ForInStep.done ⟨some (some b), PUnit.unit⟩)
        | x => do
          pure PUnit.unit
          pure (ForInStep.yield ⟨none, PUnit.unit⟩)

Tactic:
apply monotone_forIn

Result:
case hmono₁.hmono
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
⊢ monotone fun x a r =>
    let r := r.snd;
    do
    let __do_lift ← f x a
    match __do_lift with
      | some b => pure (ForInStep.done ⟨some (some b), PUnit.unit⟩)
      | x => do
        pure PUnit.unit
        pure (ForInStep.yield ⟨none, PUnit.unit⟩)

Proof state:
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
⊢ monotone fun x => Array.findSomeM? (f x) xs

Tactic:
unfold Array.findSomeM?

Result:
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
⊢ monotone fun x => do
    let r ←
      forIn xs ⟨none, PUnit.unit⟩ fun a r =>
          let r := r.snd;
          do
          let __do_lift ← f x a
          match __do_lift with
            | some b => pure (ForInStep.done ⟨some (some b), PUnit.unit⟩)
            | x => do
              pure PUnit.unit
              pure (ForInStep.yield ⟨none, PUnit.unit⟩)
    let __do_jp : PUnit → m (Option β) := fun y => pure none
    match r.fst with
      | none => do
        let y ← pure PUnit.unit
        __do_jp y
      | some a => pure a

Proof state:
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
⊢ monotone fun x => do
    let r ←
      forIn xs ⟨none, PUnit.unit⟩ fun a r =>
          let r := r.snd;
          do
          let __do_lift ← f x a
          match __do_lift with
            | some b => pure (ForInStep.done ⟨some (some b), PUnit.unit⟩)
            | x => do
              pure PUnit.unit
              pure (ForInStep.yield ⟨none, PUnit.unit⟩)
    let __do_jp : PUnit → m (Option β) := fun y => pure none
    match r.fst with
      | none => do
        let y ← pure PUnit.unit
        __do_jp y
      | some a => pure a

Tactic:
apply monotone_bind

Result:
case hmono₁
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
⊢ monotone fun x =>
    forIn xs ⟨none, PUnit.unit⟩ fun a r =>
      let r := r.snd;
      do
      let __do_lift ← f x a
      match __do_lift with
        | some b => pure (ForInStep.done ⟨some (some b), PUnit.unit⟩)
        | x => do
          pure PUnit.unit
          pure (ForInStep.yield ⟨none, PUnit.unit⟩)

case hmono₂
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
⊢ monotone fun x r =>
    let __do_jp := fun y => pure none;
    match r.fst with
    | none => do
      let y ← pure PUnit.unit
      __do_jp y
    | some a => pure a