Skip to content

Instantly share code, notes, and snippets.

@NotJustAnna
Created May 11, 2019 10:53
Show Gist options
  • Save NotJustAnna/4d49b46f079c4a0cda708013260ddf0e to your computer and use it in GitHub Desktop.
Save NotJustAnna/4d49b46f079c4a0cda708013260ddf0e to your computer and use it in GitHub Desktop.
import java.io.File
import java.util.concurrent.atomic.AtomicLong
fun walk(vararg files: File, onFile: (File) -> Unit) {
for (file in files) if (file.isDirectory) walk(onFile = onFile, files = *file.listFiles()) else onFile(file)
}
val charCount = AtomicLong()
val lineCount = AtomicLong()
walk(*File(".").listFiles()) {
when (it.extension) {
"kt", "java" -> {
val text = it.readText()
charCount.addAndGet(text.length.toLong())
lineCount.addAndGet(text.count { it == '\n' }.toLong())
}
}
}
println("charCount = $charCount; lineCount = $lineCount")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment