In functional programming there is such a thing as purity of functions and composition. During calculations inside functions, the values ​​of the variables of the external world do not change. We perform calculations in one function, and the result is passed on to another function. In javascript, you can take as an example:
[].map().reduce();
They are all connected by the essence of Array. The processed array values ​​are transferred from the map () functor to reduce (). I would like to know how to write such functions? How are they arranged inside, how is the composition carried out in them (“gluing” through a point)?
UPDATE
Approximately such a principle?
var Test = function() { var map = function() { console.log('map'); return new Test(); }; var reduce = function() { console.log('reduce'); return new Test(); }; return { map : map, reduce : reduce }; }; var test = new Test(); test.map().reduce() // map // reduce
Or somehow still different?
return
from Test - and for the rest it is this - Grundy