--

That doesn't make it bad though. Any function is just a wrapper around some other code.

If you need to apply a function to a collection of values, why not use map? It is one line, it does exactly what it says it does, and it is unlikely to have bugs because it is a built-in function. What is the benefit of writing a loop that takes several lines, includes irrelevant loop variables, and for all you know might actually be doing something slightly different to whatever you are assuming it is doing?

Of course, if you actually have some genuinely complex loop logic and try to shoehorn it into a convoluted map of maps just for the sake of avoiding a loop, that becomes a lot more questionable. Horses for courses.

--

--

Martin McBride
Martin McBride

Responses (1)