Michele Stieven
1 min readJul 10, 2021

--

Hi! Function composition is always associative by definition: it means that it doesn't matter what you combine first, as long as the order in which you compose them is the same then the operation is the same.

It does NOT mean that applying F after G is the same as applying G after F. Think of associativity as of using parenthesis :) If you have 3 functions (F, G, H) and you call F and then you pass the result to the composition of G and H, it's exactly the same as calling the composition of F and G and passing the result to H. It's literally the same operation: call F, then call G, then call H. You see it visually when using helpers like "compose" or "pipe".

If you had a division, like you say, you would have a problem in either case.

A function is not a monoid: it's an element of the monoid! A monoid which has functions as elements (you should consider functions which work on the same types), composition as the binary associative operation, and Identity Function (x => x) as unit.

--

--

No responses yet