Initial commit
This commit is contained in:
@@ -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() }
|
||||
}
|
||||
Reference in New Issue
Block a user