Libraries anvil lang iterator

class iterator
extends anvil.lang.object
Iterator generates ordered series of (keys and) values. These keys and values can be retrived one at a time.

Constructor
iterator(object value)
Creates new iterator from given value.


Methods

map both()
Returns next key and element as map.

boolean hasMore()
Checks if there are more elements available.

boolean hasNext()
Checks if there are more elements available.

iterator inject(object value)
Injects a value to iterator. Injected value is retrivable inside generator with anvil.lang.eject().

string join()
string join(string clue)
Joins the elements of iterator together with given clue.
Parameters clue -  Clue to join with, default is ", ".

object key()
Takes the key of next element. This method must be called before next().

object next()
Retrieves the next element from iterator.

object purge()
Iterates to end of iterator and returns last element. If iterator didn't have any more elements, returns undefined.

iterator reverse()
Creates a new iterator which contains the rest of remainig elements (and keys) of this iterator reversed. Operation exhausts this iterator.

boolean skip()
Skips the next element
boolean skip(int amount)
Skips up to given amount of elements
Parameters amount -  Number of elements to skip
Returns true if there are still more elements

iterator sort()
iterator sort(object comparator)
Sorts the elements in this iterator using given comparator function, if comparator function is omitted natural ordering is used. This operation unfolds the iterator to tree, and returns depth-first iterator to generated tree.
Parameters comparator -  Callable comparator, receiving parameters (value1, value2)


Operators

boolean (boolean)self
Returns true if there are more elements available

object *self
Returns next element from iterator.