Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An Iterator that cycles trough the given elements
class CycleIterator[B <: A, +A](elements: Iterable[B]) extends Iterator[A] {
var iterator: Iterator[B] = Iterator.empty
def hasNext: Boolean = {
if (!iterator.hasNext) {
iterator = elements.iterator
def next(): A =
object CycleIterator {
def apply[B <: A, A](xs: Iterable[B]): CycleIterator[B, A] = new CycleIterator[B, A](xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment