Created
May 11, 2019 10:53
-
-
Save NotJustAnna/4d49b46f079c4a0cda708013260ddf0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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