Composition more readable and easier to name we is going to ceate a compose
function we can use to avoid have To manually nest our transducer calls.
We ' ll also go over semantically naming your compose
functions for extra readability.
Nested Style:
Import {doublethenumber, evenonly} from ". /utils "; Const Map= XF = Reducer = { return(accumulation, value) = { returnReducer (accumulation, XF (value)); };}; Const filter= predicate = Reducer = { return(accumulation, value) = { if(predicate (value))returnreducer (accumulation, value); returnaccumulation; };}; Const Isevenfilter=filter (evenonly); Const Isnot2filter= Filter (val = Val!== 2); Const DOUBLEMAP=map (doublethenumber); Const Pushreducer= (accumulation, value) = ={Accumulation.push (value); returnaccumulation;}; [1,2,3,4].reduce (Isnot2filter (Isevenfilter (Doublemap (Pushreducer))), []);
Compose function:
Import {filter, map, Evenonly, doublethenumber} from ". /utils "; Const DOUBLEMAP=map (doublethenumber); Const Isevenfilter=filter (evenonly); Const Isnot2filter= Filter (val = Val!== 2); Const Pushreducer= (accumulation, value) = ={Accumulation.push (value); returnaccumulation;}; [1, 2, 3, 4].reduce (Isnot2filter (Isevenfilter (Doublemap (Pushreducer))), []);//Compose (f,g) (x) = = = F (g (x));////Compose (Isnot2filter, Isevenfilter, Doublemap) (pushreducer) = = =//Isnot2filter (Isevenfilter (Doublemap (Pushreducer)));Const Compose= (... functions) = =Functions.reduce ((accumulation, FN)=(.... args)= = Accumulation (fn (... args)), x =x); [1, 2, 3, 4].reduce (Compose (Isnot2filter, Isevenfilter, Doublemap) (Pushreducer), [],); /*?*/
[Javascript] Improve composition with the Compose Combinator