Created
September 11, 2022 17:41
-
-
Save gkthiruvathukal/3844b239e6868cacbc066bd0074ae93b 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 = 1 to Int.MaxValue | |
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