In my project I've defined the following extension...
# arrow
j
In my project I've defined the following extensions to avoid having to declare the id monad on Reader map and flatmap.
Copy code
/**
 * 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?
s
Yes, you can use
Reader
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.kt
j
👍
@Chris Myers
👍 1