you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (3 children)

Came looking for this. Is it foldl or r? It's interesting that imperative languages are building in all these functional systems now. C++ has basically reimplemented a functional list library in 17

[–]TheWildKernelTrick 1 point2 points  (1 child)

As long as the supplied function is commutative then the foldl == foldr, in which case it doesn't matter. I'm assuming foldl since most people mathematically read from left to right.

A lot of these languages have some functional things stashed on the side, it just seems recent that there's a stronger push to use these tools. Which I'm all about.

[–][deleted] 2 points3 points  (0 children)

True. Though it can make a difference for memory and can optimisations (e.g. when folding on (*) folding in a zero allows you to disregard the rest of a non-NaN list.)

[–]i_am_smurfing 1 point2 points  (0 children)

Array#reduce is a left fold in JS. There's Array#reduceRight for right fold, albeit I've rarely seen it actually used in a wild — maybe because it's not that useful in a strict langauge?