next prev up top content index

8 Collections

Iteration Stability and Natural Order

A collection is stable under iteration if any two iterations over the collection are guaranteed to produce the same values in the same order in the absence of modifications to the table. If this guarantee does not hold, the collection is unstable under iteration.

Sequences are required to be stable under iteration. Explicit key collections may or may not be stable under iteration.

The order in which elements and keys are enumerated by the iteration protocol for a particular iteration is known as the natural order for that iteration over the collection. If a collection is stable under iteration, then every iteration over that collection will have the same natural order, and we may speak of the natural order of the collection itself. Most of the operations on collections are required to operate in natural order, usually for the purpose of understanding interactions among side effects.