Re:Mindset Shifts for Functional Programming
by janetacarr on Wednesday April 05, 2023 @10:10AM
(#35454529)
Agreed, 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. :)
Re:Mindset Shifts for Functional Programming
by ballenf on Wednesday April 05, 2023 @10:30AM
(#35454887)
I 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.
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.