EsCollectionIterator
Description
A class useful for getting items, one at a time, from a <Collection> object. The <Collection> object is only required to implement #do:
If the object iterated over is changed during the iteration, the behavior is unspecified.
The <EsCollectionIterator> instance is initially positioned before the first element.Before accessing the first element the iterator must thus be advanced using #moveNext to point to the first element. If no element is left, then #moveNext returns false, and all further calls to #moveNext will also return false.
The @current value must not be accessed before calling #moveNext
or after a call to #moveNext has returned false.
A typical usage of an <EsCollectionIterator> looks as follows:
| it |

it := collection iterator.
[it moveNext] whileTrue: [self use: it current].
Instance State
  • collection: <Collection> being iterated
  • current: <Object> current element
  • atEnd: <Boolean> is stream at end
  • semaphore: <Semaphore>
  • coroutine: <Process>
Class Methods
<details> on:
<pre><code> Answer a new iterator over @aCollection
Arguments:
aCollection - <Collection>
Answers:
<EsCollectionIterator>
</code></pre> </details>
Instance Methods
<details> current
<pre><code> The current element.
If the iterator has not yet been moved to the first element (#moveNext has not been called yet),
or if the iterator has been moved past the last element. (#moveNext has answered false),
then @current is unspecified.

The #current getter should keep its value until the next call to #moveNext, even if an underlying collection changes.
After a successful call to #moveNext, the user doesn't need to cache the current value, but can keep reading it from the iterator.

Answers:
<Object>
</code></pre> </details>
<details> moveNext
<pre><code> Advances the iterator to the next element of the iteration.
Should be called before reading @current.
If the call to #moveNext answers `true`,
then @current will contain the next element of the iteration
until #moveNext is called again.
If the call answers `false`, there are no further elements
and @current should not be used any more.

It is safe to call #moveNext after it has already answered `false`,
but it must keep returning `false` and not have any other effect.

A call to #moveNext may raise an exception for various reasons,
including a concurrent change to an underlying collection.
If that happens, the iterator may be in an inconsistent
state, and any further behavior of the iterator is unspecified,
including the effect of reading @current.

Answers:
<Boolean>
</code></pre> </details>
Last modified date: 04/21/2022