1
0

Initial commit

This commit is contained in:
2020-12-01 02:12:55 +01:00
commit de750de96a
20 changed files with 516 additions and 0 deletions
@@ -0,0 +1,27 @@
@file:Suppress("unused", "MemberVisibilityCanBePrivate")
package be.vandewalleh.aoc.utils
import java.nio.file.Files
import java.nio.file.Path
import kotlin.streams.asSequence
object Resources {
private fun path(name: String): Path {
val url = if (name.startsWith('/')) javaClass.getResource(name)
else javaClass.getResource("/$name")
return Path.of(url.toURI())
}
private fun Path.lines() = Files.lines(this)
.asSequence()
.filter { it.isNotBlank() }
.map { it.trim() }
private fun Path.text() = Files.readString(this).trim()
fun text(name: String) = path(name).text()
fun lines(name: String) = path(name).lines()
fun csv(name: String) = path(name).text().splitToSequence(",")
fun csvLong(name: String) = csv(name).map { it.toLong() }
}