Rewriting functions with fold and reduce
11 minute read Published:
How to use fold and reduce to rewrite any function that operates on lists
Introduction In this post, I will explain how it is possible to use fold(in Haskell) or reduce(in JavaScript) to rewrite some common array functions to get a basic understanding of how they work and how much you can do with it.
So, if you want to learn how fold/reduce work and what a powerful function it is, this post is for you.
How does fold/reduce work? fold/reduce iterates over a list and operates on the current element and the already processed ones.