Skip to content

Instantly share code, notes, and snippets.

@klaeufer
Forked from gkthiruvathukal/KLSigPipeFun.scala
Created September 11, 2022 22:37
Show Gist options
  • Save klaeufer/5070185ad5bd3760c6fc5e8a5d57fe04 to your computer and use it in GitHub Desktop.
Save klaeufer/5070185ad5bd3760c6fc5e8a5d57fe04 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 = 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