[erlang-questions] foldl vs foldr and ++

Ulf Wiger ulf@REDACTED
Fri May 11 11:27:29 CEST 2012


On 11 May 2012, at 04:02, Richard O'Keefe wrote:

> This can be written more efficiently, but it's best of all
> just not to reverse the string in the first place.  Keep
> the code at a level where you can see what's going on well
> enough to spot the really _big_ efficiency gains.

And this is of course the really important difference between
foldr() and foldl():

- in which order do you want to process the list?
- if you build a list in the accumulator, in which order do you want it?

For most practical purposes, one should assume that they 
both both do their job efficiently.

BR,
Ulf

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com






More information about the erlang-questions mailing list