DEV Community

Discussion on: Dependency injection in functional programming

Collapse
 
patroza profile image
Patrick Roza • Edited

Thanks for the response!

why not Lodash or Ramda

I'm a fan especially of Rambda (notice bd), I use it a lot and like it. I throw in some Lodash once in a while, when I need some of their helpers for a specific problem.

The problem with the various ways of composition in Typescript is some loss of (generic) type inference. I think Lodash barely tries. Rambda does way better, I would have to look into Ramda to check how they fare. If TS will receive placeholder generic types, this might improve.

Such type inference is very valuable to me, it is one of the things I like the most about Typescript; types are optional - although I use them extensively, and the inference goes a very long way, together with derivative types, to potentially reduce a lot of manual typing (Pick, Omit, Partial, NonNullable, ReturnType, to name few built-in. But one can go extreme; github.com/pirix-gh/ts-toolbelt)

So far i'm using github.com/gcanti/fp-ts (and all it's friends like io-ts etc). But i'm still not sure of the verbose syntax. I can't wait until the pipe operator (|>) in JS/TS lands, in the hopes that will resolve some of the boilerplate and verbosity. But maybe i'm really just ready for Kotlin, F# and friends..

What is the purpose of late-binding (assuming the dependencies are immutable references)

I like to be able to define less abstract functions below my most abstract one (in class world, basically from Public to Private methods). Without late-binding I would have to define those functions above instead.
Also it helps a little bit with some annoying cyclic references between files at times - although those should generally be avoided anyway.

I was referring to the difference between

I agree, but that means I still don't understand the sentence.

I read it as:
"If you do this:

val todos = repository.getUserTodos(userId)
getCompletedTodos(todos, userId)
Enter fullscreen mode Exit fullscreen mode

You essentially push business logic to the outer layers, for the sake of having a functional core."

But I don't see how doing this is moving business logic.
Perhaps i'm misreading ;-)

Thread Thread
 
psfeng profile image
Pin-Sho Feng

Thanks a lot for this very high quality response, it all makes sense. I'm very intrigued by TypeScript right now to be honest, will give it a try :)