3 ms·
> If your language uses strict evaluation (like most languages), it probably makes sense to use a left fold on lists. The standard libraries of strict language
by pansa2 7y ago
> If your language uses strict evaluation (like most languages), it probably makes sense to use a left fold on lists.
The standard libraries of strict languages agree. Python's `functools.reduce` and JavaScript's `Array.prototype.reduce` perform strict left folds equivalent to Haskell's `foldl'`.
Interestingly, JavaScript also has `Array.prototype.reduceRight`, but it's not equivalent to a `foldr`. It processes the list from right-to-left, so is approximately equivalent to `reverse` followed by `foldl'`.
- skrebbel 7y ago> Interestingly, JavaScript also has `Array.prototype.reduceRight`, but it's not equivalent to a `foldr`. It processes the list from right-to-left, so is approximately equivalent to `reverse` followed by `foldl'`. I don't understand how that's different in practice. Can you elaborate?