[Functional Programming] 1. Function modelling -- Combine functions
Let's say we have two fucntions: const toUpper = s => s.toUpperCase(); const exclaim = s => `${s}!`; We want to combine those. But function itself doesn't give us method to combine tow functions. Therefore we can create a Monoid to combine function: const Fn = run => ({ run, concat(otherFn) { } }) So 'Fn' take a 'run' function as arguement and because we want to combine different function, we need to implement the interface for monoid 'concat'. Inside 'concat' function, first, it should return 'Fn', so that we can compose later. const Fn = run => ({ run, concat(otherFn) { return Fn() } })