This is where the magic happens. To efficiently traverse into
Chain.Concat instances, we build our own stack on the heap. When
we descend into the LHS of a Concat we push the RHS onto this
stack, so that when we exhaust the LHS we will remember to get an
iterator from the RHS too.
As mentioned earlier, iterating over ChainIterator[A] is an O(n)
operation, that also consumes O(n) heap (the previously-mentioned
stack.)
Linear Supertypes
Iterator[A], TraversableOnce[A], GenTraversableOnce[A], AnyRef, Any
Iterator for a Chain[A].
This is where the magic happens. To efficiently traverse into Chain.Concat instances, we build our own stack on the heap. When we descend into the LHS of a Concat we push the RHS onto this stack, so that when we exhaust the LHS we will remember to get an iterator from the RHS too.
As mentioned earlier, iterating over ChainIterator[A] is an O(n) operation, that also consumes O(n) heap (the previously-mentioned stack.)