IIterator INTERFACE

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.

All Members


TypeNameSignature
methodhasNextpublic bool hasNext()
methodnextpublic var next()

Methods


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

  • true if there are more items to return.

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

  • The next item.