3 ms·
What's hard to understand about it? It's just x = initial for y in collection: x = f(y, x)
by _moof 17d ago
What's hard to understand about it? It's just
x = initial
for y in collection:
x = f(y, x)
- ema 17d agoIt's easy but it ain't simple. Because `f` can do arbitrary things to `x` you have to look at it just to know the general shape of the computation. Reduce gives you a lot of the flexibility of imperative programming but with that also a lot of the problems. Sometimes that's the right trade-off but it is good to be aware that it is a trade-off.
- Joker_vD 17d agoYou mean "f(x, y)", right? Half of the languages that have reduce/fold use this ordering, another half uses yours. So in effect, as some other commenter said, it's just the loop with worse syntax.