Skip to content

Instantly share code, notes, and snippets.

@gkthiruvathukal
Created September 11, 2022 17:41
Show Gist options
  • Save gkthiruvathukal/3844b239e6868cacbc066bd0074ae93b to your computer and use it in GitHub Desktop.
Save gkthiruvathukal/3844b239e6868cacbc066bd0074ae93b to your computer and use it in GitHub Desktop.
Tinkering with Konstantin's example
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