November 2017
Intermediate to advanced
386 pages
9h 22m
English
Back in Chapter 2, Thinking Functionally - A First Example, we went through an example of developing an FP-style solution for a simple problem: fixing things so a given function would work only once:
const once = func => { let done = false; return (...args) => { if (!done) { done = true; func(...args); } };};
This is a perfectly fine solution, and we have nothing to object to. We can, however, think of a variation. We could observe that the given function gets called once, but its return value gets lost. That's easy to fix, however; all we require is adding a return statement. However, that wouldn't be enough; what would the function return if called more times? We can take a page out of the memoizing solution ...
Read now
Unlock full access