I found the general rule about when to use foldr vs foldl’ a bit vague:
According to the Principle of Least Power you should use
foldl'
in preference tofoldr
when you can.
In contrast, here’s a slightly different proposition by @lexi.lambda update custom column names on renaming/dropping columns by rakeshkky · Pull Request #2933 · hasura/graphql-engine · GitHub (it’s a good read!)
When the accumulation function is strict, use foldl’ to consume the list in constant space, since the whole list is going to have to be traversed, anyway.
When the accumulation function is lazy in its second argument, use foldr to do work incrementally to improve streaming and work-saving.
Never use foldl or foldr’; they’re always worse on lists.
Note that the above only applies for lists. So maybe your rule is more general.
Also interesting wrt foldr optimization: Neil Mitchell's Blog (Haskell etc): foldr under the hood