4 ms·
Title is a little clickbaity; these are decent examples for where higher order functions may provide more clarity than for loops, but there are also good exampl
by jjnoakes 9y ago
Title is a little clickbaity; these are decent examples for where higher order functions may provide more clarity than for loops, but there are also good examples where for loops provide more clarity than higher order functions.
Knowing when to use one or the other is the important bit. Blindly ignoring one of the tools in your toolbox may not be the wisest choice.
- WorldMaker 9y agoAgreed, especially depending on the functional programming background of people involved in a project. In one project my guideline simply became `for (of)` is welcome, `for (;;)` is not. If you are too busy worried about index numbers as `for (;;)` is, you may be missing the big picture (and doing a lot of "useless" math), `for (of)` at least is relatively high level, and with Iterable support `for (of)` gives you more room to more easily move things out of the loop and into higher-order iterable functions before the loop. Also with async/await, `for (of)` can sometimes be a lot easier to reckon with than higher order functions. People don't easily grasp Promise combinators, but `for (of) { const thing = await process() }` is readable for most everyone.