Indexed left folds #
l.foldlIdx f init start folds f over the list l from the left, passing the index of each
element plus start. Read as an automaton, it is the run of the time-dependent transition function
f : ℕ → S → X → S on the letters of l, started at time start in the state init. This file
adds the lemmas for splitting such runs to the basic List.foldlIdx API of Batteries.
Main results #
List.foldlIdx_append: folding overl₁ ++ l₂continues from the end of the fold overl₁.List.foldlIdx_map: folding over a mapped list precomposes the map.List.foldlIdx_flatten: folding over a concatenation of blocks of lengthnfolds the blocks.List.foldlIdx_ofFn: folding over the list of a tuple isFin.foldlwith shifted indices.List.foldl_ofFn: the corresponding bridge for an ordinary, unindexed fold.
theorem List.foldlIdx_flatten {α : Type u_1} {β : Type u_2} (f : ℕ → α → β → α) {n : ℕ} (L : List (List β)) (hL : ∀ l ∈ L, l.length = n) (init : α) (start : ℕ) :
Indexed folds over blocks: if every block of L has length n, the fold over the
concatenated blocks is the fold over the list of blocks that folds a whole block at each index,
the i-th block from index n * i on.