These are chat archives for ramda/ramda
That's a great question @guildwars-redhat
First off, I should say that for the purposes of writing a library, we should be using the most efficient methods available to us. In JS that often means at the bottom we need loops. Recursion is just not that efficient in JS to avoid it. But that doesn't mean loops are a good pattern for FP, even if at some level, depending on the language, they are unavoidable.
I think my main issues with loops are that they are fundamentally procedural, stateful, and serial. Procedural because they rely on executing a series of steps in a block. Stateful because they involve declaring a mutable variable that changes over time. Serial because they can't be safely parallelized without examining the internals of what the loop is doing. Contrast that with something like map, which is declarative, stateless, and parallel. You could call the function on every item in the array at once without effecting the final value, it doesn't rely on any external state, and you don't need to keep track of the details of what is happening "under the hood".
They are also the wrong level of abstraction for application code. If you're using a raw loop, I can guarantee there is a clearer solution using a higher level pattern, be it
reduce, or some more specific function. By using a loop instead you're basically rolling your own solution instead of taking advantage of these existing and well tested patterns. This adds more code that needs to be written, maintained, tested, and understood by those reading your function.
Lastly, I think , at least when you're learning, falling back to loops can end up preventing you from figuring out more idiomatic ways of doing things. You'll find the more you get used to functions like
any, etc., the less you'll feel yourself reaching for loops when you need to handle multiple pieces of data.