Last active
August 29, 2015 14:17
-
-
Save klaeufer/350ae39af27d19b156c2 to your computer and use it in GitHub Desktop.
Scala Iterator loop idiom (stateful): repeatedly produce a value until a condition is met
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
Iterator continually { | |
// ... | |
reader.readLine() | |
} takeWhile { | |
Option(_).isDefined | |
} foreach { | |
processExpr | |
} | |
replaces | |
while ((/* ... */ ; line = reader.readLine()) != null ; line) { | |
processExpr(line) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment