Documentation

Mathlib.Data.List.Flatten

Join of a list of lists #

This file proves basic properties of List.flatten, which concatenates a list of lists. It is defined in Init.Data.List.Basic.

theorem List.Sublist.flatten {α : Type u_1} {l₁ l₂ : List (List α)} (h : l₁.Sublist l₂) :
theorem List.Sublist.flatMap {α : Type u_1} {β : Type u_2} {l₁ l₂ : List α} (h : l₁.Sublist l₂) (f : αList β) :
(flatMap f l₁).Sublist (flatMap f l₂)
theorem List.drop_take_succ_eq_cons_getElem {α : Type u_1} (L : List α) (i : Nat) (h : i < L.length) :
drop i (take (i + 1) L) = [L[i]]

Taking only the first i+1 elements in a list, and then dropping the first i ones, one is left with a list of length 1 made of the i-th element of the original list.

theorem List.append_flatten_map_append {α : Type u_1} (L : List (List α)) (x : List α) :
x ++ (map (fun (x_1 : List α) => x_1 ++ x) L).flatten = (map (fun (x_1 : List α) => x ++ x_1) L).flatten ++ x

We can rebracket x ++ (l₁ ++ x) ++ (l₂ ++ x) ++ ... ++ (lₙ ++ x) to (x ++ l₁) ++ (x ++ l₂) ++ ... ++ (x ++ lₙ) ++ x where L = [l₁, l₂, ..., lₙ].