I’m having trouble continuing to use the `Reader` ...
# arrow
j
I’m having trouble continuing to use the
Reader
type after upgrading to 0.12.0. (MTL is still on 0.11.0 though). After this upgrade:
Copy code
-  val arrowFx = "io.arrow-kt:arrow-fx:0.10.5"
-  val arrowMtlData = "io.arrow-kt:arrow-mtl-data:0.10.5"
-  val arrowOptics = "io.arrow-kt:arrow-optics:0.10.5"
+  val arrowFx = "io.arrow-kt:arrow-fx:0.12.0"
+  val arrowMtlData = "io.arrow-kt:arrow-mtl-data:0.11.0"
+  val arrowOptics = "io.arrow-kt:arrow-optics:0.12.0"
I find that
reader.run(thing).value()
is no longer able to resolve
.value()
. How should it read now?
.run(thing)
is returning type
Kind<ForId, T>
2
s
mtl
is no longer actively maintained. It was an experimental module, and heavily relies on
Kind
and typeclasses which are unidiomatic in Kotlin and require a lot of weird machinery. Here are a couple examples of how you can replace
Reader
with receiver functions and how you can scope/compose the
T
dependency type of your
Reader
. - https://gist.github.com/raulraja/ac7a489c01193bcf5e8fdc59c89b5156 - https://gist.github.com/raulraja/97e2d5bf60e9d96680cf1fddcc90ee67 - https://gist.github.com/nomisRev/1f91710ebec1709d4ce8059812482624
j
Thanks
s
You're very welcome! 🙂
c
@simon.vergauwen sad to hear about
ReaderT
, could you please elaborate a bit on your explanation above? I've had a look at the examples, they are quite different from one another
r
@Carlos Fernandes ReaderT is
(Dependencies) -> F<A>
which is already covered in Kotlin by extension functions and suspension if your F is IO.
suspend Dependencies.f(): A
it’s isomorphic to
ReaderT<IO<_>, Dependencies, A>
, more ergonomic, faster and memory friendly since it avoids several layers of flatMap nesting. The examples above are examples of programs written in that style in which dependencies can be constrained with type bounds to enable syntax in the functions.
s
And
suspend Dependencies.f(): Either<E, A>
being
ReaderT<PartialEitherTOf<ForIO, E>, Dependencies, A>
1
c
Got it, thanks.
r
My test of functionall dependency injection. Is this approach ok when there is no MTL? https://github.com/Rebyrg/learningarrow/blob/main/src/test/kotlin/pl/rebyrg/learningarrow/ReaderTest.kt
r
@rebyrg that’s a great example using a custom Effect type 👏 . I still see no value for Reader compared to just making those extensions functions with your Reader argument as a receiver. Is there an advantage using Reader over extension functions?
r