Documentation

CslibFrontier.Foundations.Data.List.ModifyLast

Length and entries of List.modifyLast #

List.modifyLast f l applies f to the last entry of l and leaves the others alone. This file records the two facts that index-wise arguments about it need: the length is unchanged, and the entry at position i is f l[i] when i is the last position and l[i] otherwise. Both follow from Mathlib's List.modifyLast_concat.

Main results #

@[simp]
theorem List.length_modifyLast {α : Type u_1} (f : α → α) (l : List α) :
theorem List.getElem_modifyLast {α : Type u_1} (f : α → α) (l : List α) {i : ℕ} (hi : i < (modifyLast f l).length) :
(modifyLast f l)[i] = if i + 1 = l.length then f l[i] else l[i]

List.modifyLast f changes only the last entry, where it applies f.