I want to create a directory, then do something with the directory and finally delete it. I'm using a bracket idiom for that.
val fs: FileSystem = ???
val path = ???
ZIO.bracket[Any, Throwable, Path, Unit](
acquire = ZIO{fs.mkdirs(path); path},
release = p => ZIO.succeed(fs.delete(p, true)),
use = p => ZIO{()})
Deleting a directory is apparently an error-prone action. But release
function has to always succeed. So I have to use ZIO.succeed
which looks wrong.
How to close the resource properly?