5 ms·
I mostly agree, and proponents of FP shouldn't stress the recursion too much. When I program in Haskell, I rarely use recursion myself. Most loops are just map
by js8 4y ago
I mostly agree, and proponents of FP shouldn't stress the recursion too much.
When I program in Haskell, I rarely use recursion myself. Most loops are just maps and folds. Need to build another structure from existing structure? Foldl'. Once I understood that the value being folded can be arbitrarily complex, FP became simpler (but terser) than iterative programming for me.
- janetacarr 4y agoAgreed, I rarely reach for recursion myself when developing. Most of my transformations are map, filter, and reduce. Although from time to time, I will combine them with recursion when necessary. I find recurring from a reducing function to be great for traversing or searching trees or other recursive data structures. Usually these are accompanied by a ton of comments for the next developer. :)
- ballenf 4y agoI don't think of map operations as loops. Instead as parallel operations on elements of a list works as a better mental model for me. When learning them coming from an imperative background, it's inevitable to start with that idea, but somehow feels like a limiting model.