-
-
Save klaeufer/5070185ad5bd3760c6fc5e8a5d57fe04 to your computer and use it in GitHub Desktop.
Tinkering with Konstantin's example
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 KLSigPipeFun { | |
def main(args: Array[String]) = { | |
val lines = scala.io.Source.stdin.getLines() | |
val lineNumbers = Iterator.from(1) | |
val numberedLines = lineNumbers.zip(lines) | |
val okLines = numberedLines takeWhile { _ => !scala.sys.process.stdout.checkError() } | |
val outLines = okLines map { case (number, line) => println(number + ":" + line) } | |
println(outLines.length + " lines counted") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment