Hi, I’m starting with Kotlin and was wondering wha...
# arrow
r
Hi, I’m starting with Kotlin and was wondering what was the “go to” for dependency injection… I saw that Kotlin has classic “DI containers” but was wondering if Arrow provided a more FP solution. (Environmental effects à la ZIO, or a more classic approach à la ReaderT)
r
Hi @Roger Cyr, Arrow used to have Reader but we found it mostly useless over time given Kotlin natively supports extension receivers and suspension. For example
suspend Foo.doStuff(): Unit
is equivalent to
ReaderT<IO, Foo, Unit>
and can also be passed as value and has type of
suspend Foo.() -> Unit
. this also applies to other names like “Environmental Effects” which I think just means here the suspended effect has access to the scope of its receiver and this receiver can be passed in any call site as argument.
Additionally those abstractions rewrap functions which means double boxing for the most part, this is also a reason why we tossed them in Arrow as general abstractions
I have some old examples of using receivers for DI here in case it helps. https://gist.github.com/raulraja/97e2d5bf60e9d96680cf1fddcc90ee67 .
r
Wow, thank you! This is going to help me a lot 🙂
👍 1