jem
06/20/2020, 5:15 AM/**
* Extension function that fixes `Reader` so that you can `map` without needing to pass
* `arrow.core.Id.monad()` explicitly.
*/
fun <D, A, B> Reader<D, A>.map(f: (A) -> B): Reader<D, B> {
return this.map(arrow.core.Id.monad()) { f(it) }
}
/**
* Extension function that fixes `Reader` so that you can `flatMap` without needing to pass
* `arrow.core.Id.monad()` explicitly.
*/
fun <D, A, B> Reader<D, A>.flatMap(f: (A) -> KleisliOf<D, ForId, B>): Reader<D, B> {
return this.flatMap(arrow.core.Id.monad()) { f(it) }
}
Is there any blocker for actually just making Reader work this way in the lib? Is there any other monad instance that is valid for Reader?simon.vergauwen
06/20/2020, 10:00 AMReader
with IO
to combine it with effects, or any other Monad
. It’s often composed together with EitherT
and IO
as well.
To describe a program that has a dependency, and runs effect-fully with a domain error or success value as result.
These APIs should already be available as extensions over ReaderT<ForId
actually, and they should be importable as extensions.
https://github.com/arrow-kt/arrow-incubator/blob/master/arrow-mtl-data/src/main/kotlin/arrow/mtl/Reader.ktsimon.vergauwen
06/20/2020, 10:01 AMReader
with extensions functions.
Example/docs: https://gist.github.com/nomisRev/1f91710ebec1709d4ce8059812482624
https://github.com/arrow-kt/arrow-fx/tree/master/arrow-fx-coroutines#suspend-r---ajem
06/20/2020, 12:06 PMjem
06/23/2020, 1:11 AM