Skip to content

Instantly share code, notes, and snippets.

@JakeCoxon
Created January 13, 2014 17:53
Show Gist options
  • Save JakeCoxon/8404793 to your computer and use it in GitHub Desktop.
Save JakeCoxon/8404793 to your computer and use it in GitHub Desktop.
An iterator that iterates two secondary iterators in parallel
class CombinedIterator[A, B](first: Iterator[A], second: Iterator[B]) extends Iterator[(Option[A], Option[B])] {
def hasNext = first.hasNext || second.hasNext
def next = (if (first.hasNext) Some(first.next) else None, if (second.hasNext) Some(second.next) else None)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment