Skip to content

Instantly share code, notes, and snippets.

@programaths
Created September 15, 2016 19:21
Show Gist options
  • Save programaths/505b5eafd8809a93e9a1d9a2dacdf315 to your computer and use it in GitHub Desktop.
Save programaths/505b5eafd8809a93e9a1d9a2dacdf315 to your computer and use it in GitHub Desktop.
A functional line count.
import java.io.File
fun main(args: Array<String>) {
args.map { name -> File(name) }
.filter { file -> file.isFile }
.map { file -> Pair(file.name, file.readLines().partition { line -> line.trim().isEmpty() }) }
.forEach {
val name = it.first
val (filledLines,emptyLines) = it.second
println("$name: ${filledLines.size+emptyLines.size} total, ${emptyLines.size} empty")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment