3 ms·
Which languages are you reading them in? For me the argument holds in practice as well. I'm mostly reading my combinators in Haskell, and the loops in Python
by eru 7y ago
Which languages are you reading them in?
For me the argument holds in practice as well. I'm mostly reading my combinators in Haskell, and the loops in Python or some curly brace language.
If you use a general purpose combinator like mapAccumL that has almost as much power as a loop, you don't get that much extra readability compared to the loop.
It's still a bit better, because that combinator still has to process one element of your list for each run through it's "body"; and it clearly warns you by it's very name that it's not just a filter or map, so there's less possibility of confusing it for something simpler.
And, of course, not all loops are created equal. When applicable, for-each loops are much cleaner than classic C-style for-loops for example.