Skip to content

Instantly share code, notes, and snippets.

@dlwh
Created May 2, 2009 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlwh/105659 to your computer and use it in GitHub Desktop.
Save dlwh/105659 to your computer and use it in GitHub Desktop.
def producerToIterator[L](prod : =>L):Iterator[L] = new Iterator[L] {
private var current: Option[L] = None
def hasNext = current != None || {
current = prod match {
case null => None
case x => Some(x);
};
current != None;
}
def next = {
hasNext;
val result = current;
current = None;
result.get
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment