PhBastiani
06/12/2020, 1:40 PMcopy
method is the most idiomatic.
I noticed a wrong proposal of the IDE: sometimes IntelliJ proposes to remove the suspend
modifier when it is necessary 😕
Feedback appreciated !stojan
06/12/2020, 2:16 PMresourcedCopy
can be a suspend
function, instead of regular fun returning a suspend
lambda 🙂PhBastiani
06/12/2020, 3:08 PMuse
in the main
method...
Other point : I don't understand why i cannot write
Resource({ fileConsumer(src) }, InputStream::close)
instead of
Resource({ fileConsumer(src) }, ::close)
like in your video @Jorge CastilloJorge Castillo
06/12/2020, 3:26 PMInputStream::close
and see whether it worksJorge Castillo
06/12/2020, 3:31 PMclass File {
suspend fun close(): Unit = TODO()
companion object {
fun openFile(path: String): File = File()
}
}
val resources = listOf(
Resource({ openFile("path1") }, File::close),
Resource({ openFile("path2") }, File::close),
Resource({ openFile("path3") }, File::close)
)
val fileContents: List<String> = resources.parTraverse(IOPool) { files ->
files.use { file -> file.toString() }
}
simon.vergauwen
06/12/2020, 3:45 PMContinuation
parameter, so the Kotlin compiler needs to explicitly translate that for you. Which it currently doesn’t support.
That’d be a great and simple use-case for a compiler plugin, which I’d love to use! 😄simon.vergauwen
06/12/2020, 3:48 PMtailrec suspend fun
is very idiomatic IMO. I’ve been using it in lost of places already in the library, and also in the stuff I’m currently building on top.
That’s the cool thing about not having the IO
wrapper anymore, is that we can use regular tailrec
. I’m also going to introduce a PR in the next day to expose trampoline
so you could do the same as IO
does internally in cases where you cannot write a tailrec
function.PhBastiani
06/12/2020, 3:52 PMtailrec
works like a charm with your DSL.PhBastiani
06/12/2020, 11:23 PM