Skip to content

Instantly share code, notes, and snippets.

@klaeufer
Forked from gkthiruvathukal/KLSigPipeFun.scala
Last active March 13, 2026 21:15
Show Gist options
  • Select an option

  • Save klaeufer/5070185ad5bd3760c6fc5e8a5d57fe04 to your computer and use it in GitHub Desktop.

Select an option

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(s"$number: line")
println(s"${outLines.length} lines counted")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment