Of course I wouldn’t label it as a “violation” of functional principle. In terms of readability and composability, assuming similar performance profiles, I think (based on experience) that a series of simple transforming functions are easier to parse than a complex fold in a similar vein to a fold being easier to parse than a loop (most of the time). Part of “functional thinking” is breaking down algorithms into known function patterns, so if you can identify that a complex loop is e.g. “a map followed by a groupby followed by a filter”, that’s considered an advantage compared to creating a new fold function that does these operations.
Am I right that both functions are not tail recursive?
It looks like they could be TRMC?
1 Like