KIO
KIO copied to clipboard
R as context receiver for functions
Hi there! As first thing very nice project for who like me would like to move to ZIO but is stuck with Kotlin 😛
I was playing around with it and not sure if I wasn't unable to find it or there is a reason to not have the R
parameter of the KIO
in the functions for flatMap
/map
Something like:
inline fun <R, E, A, O> KIO<R, E, A>.flatMapC(crossinline fn: R.(A) -> KIO<R, E, O>) = flatMap { value ->
askPure<R>().flatMap { ctx -> fn(ctx, value) }
}
so that one can do:
data class Context(val messageId: String)
val program: KIO<Context, Throwable, String> = TODO()
program.flatMapC { value -> println("messageId: $messageId") }
I couldn't find something similar, but seems a nice way of accessing it taking advantage of Kotlin features