dartora

IterationHolder

IterationHolder is a concrete subclass of IterationBase<E> that concatenates multiple mutable lists into a single logical list. It allows you to build large sequences out of smaller chunks without copying elements. Each chunk must itself be an IterationBase<E>, so that IterationHolder can delegate insertion, removal and element access to its children.

Constructor

IterationHolder({
  required List<IterationBase<E>> items,
  int startIndex = 0,
  int indexTake = 0,
})

On construction, IterationHolder computes the total length of all sub‑lists and caches it in _sourceLength.

Internal state

Field Description
items The list of child IterationBase<E> instances.
_sourceLength Caches the total number of elements across all children. Updated whenever elements are added or removed.
startIndex / indexTake Window offsets inherited from IterationBase.

Hook implementations

IterationHolder overrides the hooks from IterationBase to operate across multiple sub‑lists:

Mutation logic

IterationHolder implements sourceInsertAll and removeAction by delegating to the appropriate child sub‑lists:

Because each child is itself an IterationBase<E>, removal or insertion may change its length. The holder uses sourceLengthBeenModified to keep its cached _sourceLength in sync.

Usage

Use IterationHolder when you need to treat several lists as one large list without copying. Examples include storing extra values for a LargeList (which uses a sub‑list for extras) or building composite views for search results. Mutations performed on an IterationHolder are forwarded to the appropriate child list, so the underlying storage remains consistent.