DEV Community

Discussion on: Getting started with fp-ts: Functor

Collapse
 
herlevsen profile image
Jens Ahlsten Herlevsen

"How can we compose two generic functions f: (a: A) => B and g: (c: C) => D"

Don't you mean "g: (b: B) => C"?

And thank you for writing these articles, they are very helpful :-)

Collapse
 
eoksni profile image
Dmitry Mazurok • Edited

Composing f: (a: A) => B and g: (b: B) => C is trivial by normal function composition.

What is challenging is composing f and g when output type of f isn't the same as input type of g. And that is impossible to do if these output-input types are completely arbitrary.

So what we do is we try to introduce some dependency between them ("what if output of f is F<input of g>?") and see if we can somehow compose them NOW, with that constraint in place.

Turns out we CAN - if F is a functor.

Collapse
 
pradeepdas profile image
pradeepdas

Taking the concrete problem of two generic functions f: (a: A) => B and g: (c: C) => D

Can you show how a Response Functor solves the composition when B != C