January 2020
Intermediate to advanced
470 pages
11h 13m
English
Essentially, what we want is to transform each function (testOdd(), duplicate(), and so on) into a reducing operation that will call the following reducer. A couple of higher-order functions will help; one for mapping functions and an other for filtering ones. With this idea, the result of an operation will be passed to the next one, avoiding intermediate arrays:
const mapTR = fn => reducer => (accum, value) => reducer(accum, fn(value));const filterTR = fn => reducer => (accum, value) => fn(value) ? reducer(accum, value) : accum;
These two transforming functions are transducers: functions that accept a reducing function and return a new reducing function.
Read now
Unlock full access