commonMain.com.xebia.functional.xef.loaders.TextLoader.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xef-filesystem-jvm Show documentation
Show all versions of xef-filesystem-jvm Show documentation
Building applications with LLMs through composability in Kotlin
package com.xebia.functional.xef.loaders
import com.xebia.functional.xef.io.DEFAULT
import okio.FileSystem
import okio.Path
/** Creates a TextLoader based on a Path */
suspend fun TextLoader(
filePath: Path,
fileSystem: FileSystem = FileSystem.DEFAULT
): BaseLoader = object : BaseLoader {
override suspend fun load(): List =
buildList {
fileSystem.read(filePath) {
while (true) {
val line = readUtf8Line() ?: break
add(line)
}
}
}
}