A stateful object that projects an iteration-facing view over another object.
Normally a user would call an iterator this way: while(iterator.hasNext()){
iterator.next(); // Get next
}
But Julian also provides language-level support for this pattern with its foreach statement: // In each iteration, engine first calls hasNext(), then
// if true, calls next() and assigns the value to ele.
for (var ele : iterator) {
ele.fun();
}
Also, if variable iterator
in the foreach's data source is an IIterable, the engine will first call IIterable.getIterator() to obtain a new instance of iterator.
Type | Name | Signature |
---|---|---|
method | hasNext | public bool hasNext() |
method | next | public var next() |
public bool hasNext()
Check if the iteration is reaching the end. If this returns true, the caller may proceed to make at least one more call of next().
Returns
public var next()
Get the next item. This method is usually called after hasNext returns true
, but in a multi-threaded context there is no guarantee on what this would actually return, regardless of the result by hasNext()
.
Returns