Created
November 24, 2010 23:58
-
-
Save nuttycom/714663 to your computer and use it in GitHub Desktop.
What Iterator.iterate should have been.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Bah { | |
def iterate[T](t: T)(f: T => Option[T]): Iterator[T] = new Iterator { | |
var next = Some(t) | |
override def hasNext = next.isDefined | |
override def next = { | |
val result = next.get | |
next = f(result) | |
result | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment