I can’t find Reader and ReaderApi in arrow 0.10.3,...
# arrow
f
I can’t find Reader and ReaderApi in arrow 0.10.3, where is it? 🤯
j
Latest master (don't think mtl has changed since 0.10.3) has it in
arrow-mtl
and more specifically in this file: https://github.com/arrow-kt/arrow/blob/master/modules/mtl/arrow-mtl-data/src/main/kotlin/arrow/mtl/Reader.kt
f
Oh thx, what is mtl?
r
MTL is where the monad transformers and their type classes are including Reader which is an alias for Kleisli
arrow 1
j
mtl is short hand for monad transformer library which is what it is called in haskell from where this pattern originated. mtl usually spans monad transformers and typeclasses associated with those. The purpose of transfomers is the change the behaviour of some monad to add on some other behaviour. For example
Reader
is a typealias for
Kleisli Id
which can be translated as "extend Id with Reader abilities"
r
it’s still an experimental library since we plan on assimilating some of those features with other techniques that are more ergonomic in Kotlin
The reader monad for example offers no benefit over extension functions unless you are doing polymorphism
f
I'm trying to use them for my UseCase, something like
Copy code
class UseCase { 
 fun exec(): Reader<Repository, List<User>>
}
it's less ergonomic than pass Repository via constructor, propably i only use for stay "functional"
j
I think the benefit of the Reader pattern only really comes into play when you have multiple functions that need the provided context and/or you want to provide the same context throughout your function hierarchy (For example readers are great to replace DI, which when done with generated sources is just plain awful imo). Using a reader just to pass an additional parameter to a single function is far worse than simply having an additional parameter.
r
@Francesco megna also in that case you may just want to use a val since a Reader is already a function
☝️ 1
f
My things is to create many UseCase with different configuration, so make DI with Reader, probably is only a style excercise
r
I guess what I’m saying that all that is the same as a top level function:
Copy code
fun Repository.users(): List<User>
which is also probably leaner allocations wise