I am using kotlin for several years now and my pro...
# announcements
p
I am using kotlin for several years now and my programming style is evolving and becoming more functional. I write way more top level functions that I did one year ago. What I ask myself is: What do I do when my functions need more dependencies? Lets say I have a file with one public top level function and it calls private functions which themselfes call other functions too. When I now need the class X and Y in
fun d(x : X, y : Y)
it's painful to change all that code just for passing them through from
fun a(x : X, y : Y)
->
fun b(x : X, y : Y)
->
fun c(x : X, y : Y)
->
fun d(x : X, y : Y)
. Are there any common approaches / patterns to solve this?
s
Dependency injection 😉
d
I think you’re describing the problem that dependency injection is designed to solve.
s
And the functional variant partially applied functions. It sucks that you lose the top level aspect but its the only way afaik.
If you can somehow group up your dependencies then you can take them as the
receiver
. This keeps it a bit under control but not very good general solution.
e
You might want to consider using Arrow: arrow-kt.io And, specifically, Dependency Injection pattern: https://arrow-kt.io/docs/patterns/dependency_injection/