-- Mathlib/.lake/packages/lean4/src/lean/Init/Internal/Order/Lemmas.lean
theorem monotone_findM?
    {m : Type → Type} [Monad m] [∀ α, PartialOrder (m α)] [MonoBind m] {α : Type}
    (f : γ → α → m Bool) (xs : Array α) (hmono : monotone f) :
    monotone (fun x => xs.findM? (f x))

Proof state:
case hmono₁.hmono.h.h
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type
f : γ → α → m Bool
xs : Array α
hmono : monotone f
y : α
r : MProd (Option (Option α)) PUnit
⊢ monotone fun x =>
    let r := r.snd;
    do
    let __do_lift ← f x y
    if __do_lift = true then pure (ForInStep.done ⟨some (some y), PUnit.unit⟩)
      else do
        pure PUnit.unit
        pure (ForInStep.yield ⟨none, PUnit.unit⟩)

Tactic:
apply monotone_bind

Result:
case hmono₁.hmono.h.h.hmono₁
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type
f : γ → α → m Bool
xs : Array α
hmono : monotone f
y : α
r : MProd (Option (Option α)) PUnit
⊢ monotone fun x => f x y

case hmono₁.hmono.h.h.hmono₂
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type
f : γ → α → m Bool
xs : Array α
hmono : monotone f
y : α
r : MProd (Option (Option α)) PUnit
⊢ monotone fun x __do_lift =>
    if __do_lift = true then pure (ForInStep.done ⟨some (some y), PUnit.unit⟩)
    else do
      pure PUnit.unit
      pure (ForInStep.yield ⟨none, PUnit.unit⟩)

Proof state:
case hmono₁.hmono.h.h.hmono₁
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type
f : γ → α → m Bool
xs : Array α
hmono : monotone f
y : α
r : MProd (Option (Option α)) PUnit
⊢ monotone fun x => f x y

Tactic:
apply monotone_apply

Result:
case hmono₁.hmono.h.h.hmono₁.h
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type
f : γ → α → m Bool
xs : Array α
hmono : monotone f
y : α
r : MProd (Option (Option α)) PUnit
⊢ monotone f

Proof state:
case hmono₂
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type
f : γ → α → m Bool
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

Tactic:
apply monotone_const

Result:
no goals

Proof state:
case hmono₁.hmono.h
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type
f : γ → α → m Bool
xs : Array α
hmono : monotone f
⊢ ∀ (y : α),
    monotone fun x r =>
      let r := r.snd;
      do
      let __do_lift ← f x y
      if __do_lift = true then pure (ForInStep.done ⟨some (some y), PUnit.unit⟩)
        else do
          pure PUnit.unit
          pure (ForInStep.yield ⟨none, PUnit.unit⟩)

Tactic:
intro y

Result:
case hmono₁.hmono.h
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type
f : γ → α → m Bool
xs : Array α
hmono : monotone f
y : α
⊢ monotone fun x r =>
    let r := r.snd;
    do
    let __do_lift ← f x y
    if __do_lift = true then pure (ForInStep.done ⟨some (some y), PUnit.unit⟩)
      else do
        pure PUnit.unit
        pure (ForInStep.yield ⟨none, PUnit.unit⟩)