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.
"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 :-)
Composing
f: (a: A) => B
andg: (b: B) => C
is trivial by normal function composition.What is challenging is composing
f
andg
when output type off
isn't the same as input type ofg
. 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
isF<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.
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