Lean4
/-- The n-th element of a `ListBlank` is well defined for all `n : ℕ`, unlike in a `List`. -/
def nth {Γ} [Inhabited Γ] (l : ListBlank Γ) (n : ℕ) : Γ :=
by
apply l.liftOn (fun l ↦ List.getI l n)
rintro l _ ⟨i, rfl⟩
rcases lt_or_ge n _ with h | h
· rw [List.getI_append _ _ _ h]
rw [List.getI_eq_default _ h]
rcases le_or_gt _ n with h₂ | h₂
· rw [List.getI_eq_default _ h₂]
rw [List.getI_eq_getElem _ h₂, List.getElem_append_right h, List.getElem_replicate]