Indexed expansion of block-emitting list recursions #
A recursion consumes a prefix, emitting a block at each step and replacing its carry by a value determined by the step index. The final suffix is passed to a terminal operation. The expansion retains the order and multiplicity of every emitted block.
Main results #
List.eq_flatMap_range_of_emit: expand such a recursion into an indexedflatMap.
theorem List.eq_flatMap_range_of_emit {α : Type u_1} {β : Type u_2} (f : ℕ → α → List α → List β) (next : ℕ → α) (emit : ℕ → α → α → List β) (finish : α → List α → List β) (reserve : ℕ) (hshort : ∀ (j : ℕ) (carry : α) (rest : List α), rest.length ≤ reserve → f j carry rest = finish carry rest) (hstep :
∀ (j : ℕ) (carry b : α) (rest : List α),
reserve < (b :: rest).length → f j carry (b :: rest) = emit j carry b ++ f (j + 1) (next j) rest) (j : ℕ) (carry : α) (rest : List α) :
Expand a block-emitting recursion that leaves reserve entries for its terminal operation.
The new carry depends only on the absolute index; it need not equal the emitted value.