/claim #220
An implementation of primitives for reading and writing files and managing processes. For the files part, there is an extension that work on any type with a PathLike
typeclass, so it is possible to apply all the methods on strings, list of strings java Paths and combination of them:
"somefolder".mkDir // creates directory somefolder
("somefolder/otherfolder" / "somefile.txt").mkFile // creates file "somefolder/otherfolder/somefile.txt"
(List("somefolder", "otherfolder") / "somefile.txt").mkFile // creates file "somefolder/otherfolder/somefile.txt"
This can be expanded to other types and be used for integration with other libraries. We can try another approach if you think it’s too “magical”.
There are a few tests involving streams that throw runtime exceptions but I feel like they should work. Am I doing something not in the intended way or is it a bug of streams? I’ve tried different ways to avoid them but it always appear.
"walk" in run {
val folder = "folder"
val path1 = folder / "path1"
val path2 = folder / "path2"
val createFolders = for {
_ <- folder.mkDir
_ <- path1.mkFile
_ <- path2.mkFile
} yield ()
assert (IOs.run(createFolders.andThen(folder.walk.map(_.runSeq))).pure._1.map(_.toString).toSet == Set("folder/path1", "folder/path2"))
}
throws kyo.package$bug$KyoBugException: Unexpected effect 'kyo.Streams' found while handling 'kyo.IOs'. Please open an issue
and
"read file as string stream" in run {
val name = "read-file-string.txt"
val text = "some text"
for
_ <- IOs(createFile(name, text))
res <- Resources.run(name.readStream())
_ <- IOs(destroyFile(name))
v <- Fibers.init(res.runSeq).map(_.get)
yield assert(v._1 == List("some text"))
end for
}
throws kyo.package$bug$KyoBugException: Unexpected effect 'kyo.Streams' found while handling 'kyo.fibersInternal$.FiberGets & kyo.IOs'. Please open an issue
.
Pablo FemenĂa
@pablf
Kyo
@getkyo