-- Mathlib/.lake/packages/lean4/src/lean/Init/Data/List/Attach.lean
theorem attach_filterMap {l : List α} {f : α → Option β} :
    (l.filterMap f).attach = l.attach.filterMap
      fun ⟨x, h⟩ => (f x).pbind (fun b m => some ⟨b, mem_filterMap.mpr ⟨x, h, m⟩⟩)

Proof state:
case cons.h_2.intro.intro
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
a : β
h✝ : a ∈ f x
h : f x = some a
⊢ map (fun x_1 => ⟨x_1.val, ⋯⟩) (attach ?m.63176) =
    ⟨a, ⋯⟩ :: filterMap ((fun x_1 => (f x_1.val).pbind fun a h => some ⟨a, ⋯⟩) ∘ fun x_1 => ⟨x_1.val, ⋯⟩) xs.attach

case cons.h_2.intro.intro
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
a : β
h✝ : a ∈ f x
h : f x = some a
⊢ (match f x with
    | none => filterMap f xs
    | some b => b :: filterMap f xs) =
    ?m.63176

α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
a : β
h✝ : a ∈ f x
h : f x = some a
⊢ List β

Tactic:
rotate_left

Result:
case cons.h_2.intro.intro
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
a : β
h✝ : a ∈ f x
h : f x = some a
⊢ (match f x with
    | none => filterMap f xs
    | some b => b :: filterMap f xs) =
    ?m.63176

α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
a : β
h✝ : a ∈ f x
h : f x = some a
⊢ List β

case cons.h_2.intro.intro
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
a : β
h✝ : a ∈ f x
h : f x = some a
⊢ map (fun x_1 => ⟨x_1.val, ⋯⟩) (attach ?m.63176) =
    ⟨a, ⋯⟩ :: filterMap ((fun x_1 => (f x_1.val).pbind fun a h => some ⟨a, ⋯⟩) ∘ fun x_1 => ⟨x_1.val, ⋯⟩) xs.attach