dartora

IterableItems

IterableItems is a convenience class that adapts a keyed map of values into a lazy sequence of those values without any transformation. It extends LargeIterable<E,E> and simply passes through each value unchanged.

Purpose

In many parts of Dartora, data is stored in a Map<String, VT> but is consumed as a sequence in a specific order defined by a list of keys. LargeIterable<VT,E> allows you to provide a transformation function (modifier) that maps from the underlying type VT to the desired type E. When the underlying type and the desired type are the same, you can use IterableItems<E> to avoid writing an identity function.

Constructor

IterableItems({
  required Map<String, E> mapped,
  required List<String> keys,
})

Internally, IterableItems simply calls the LargeIterable constructor with mapped, keys, no extras, and modifier: (e) => e. The startIndex and indexTake parameters of LargeIterable default to zero, meaning that the entire key list is visible.

Behaviour

IterableItems inherits all the features of LargeIterable:

Since IterableItems uses an identity modifier, it does not allocate new objects when iterated; it simply returns references to the existing values in the map. If you mutate the values in mapped, those mutations are visible through IterableItems.