IIterable INTERFACE

The interface to add the capability of iterating through built-in syntax.

For objects which support vector semantics, it's useful to expose an interface to allow iteration over all the held values. In particular, if the class implements this interface, the iteration can be performed directly with a foreach statement.

   class Vector : IIterable {
      IIterator getIterator() {
        return ...;
      }
   }

   Vector vector = new vector();

   for (var ele : vector) { // engine calls getIterator(), which returns a new IIterable.
     ele.fun(); // access to each element
   }


It might look confusing at the first, but it's also critical to know the difference between IIterable and IIterator. IIterable allows the object to return a view on the contained data, and thus its core method can be called unrestrictedly. IIterator, on the other hand, represents the API provided by this view, exposing the minimally necessary methods for traversing through the data set. Most importantly, IIterator is also a stateful object. The foreach statement is essentially interacting with an IIterator, not an IIterable. IIterable is useful in that it decouples the ability of iteration from the state-tracking during such iteration.

Known Extensions

All Members


TypeNameSignature
methodgetIteratorpublic IIterator getIterator()
method Eallpublic bool all(Function)
method Eanypublic bool any(Function)
method Eappendpublic IIterable append(var)
method Econcatpublic IIterable concat(var)
method Ecountpublic int count()
method Edistinctpublic IIterable distinct()
method Eexceptpublic IIterable except(System.Util.IIterable)
method Efilterpublic IIterable filter(Function)
method Efirstpublic var first()
method Efirstpublic var first(bool)
method Eflattenpublic IIterable flatten(Function)
method Eintersectpublic IIterable intersect(System.Util.IIterable)
method Elastpublic var last()
method Elastpublic var last(bool)
method Emappublic IIterable map(Function)
method Ereducepublic var reduce(var, Function)
method Eskippublic IIterable skip(int)
method Etakepublic IIterable take(int)
method EtoArraypublic var toArray()
method EtoListpublic System.Collection.List toList()
method EtoMappublic System.Collection.Map toMap(Function)
method EtoMappublic System.Collection.Map toMap(Function, Function)
method Eunionpublic IIterable union(System.Util.IIterable)
method Ezippublic IIterable zip(System.Util.IIterable, Function)

Methods


public IIterator getIterator()

Get an iterator from this object. The iterator provides methods to traverse through the entire data set contained within this object.

Returns

  • An iterator that has been properly initialized, ready to move on.