Solution (source code)

= Solution

The essential abstract methods are:
``
def hasNext: Boolean
def next(): T
``
`hasNext` reports whether another result is available. `next()` returns that result and advances; if exhausted, it throws `NoSuchElementException`. The other ordinary <iterator> operations are implemented using these primitives. An availability check must not silently discard a result visible to the client, although an adapter may need to fetch and cache underlying values in order to decide availability.<Scala 2.12 iterator API documentation>[<Iterator> abstract members hasNext and next; exhaustion contract]{ref}