Explaining map & reduce with animated examples

Hi! I created some animations to explain what happens internally with map & reduce functions.
The code is open source. Any feedback is welcome !


Heh, that’s cool looking.

1 Like

Thanks @OvermindDL1!

1 Like

Nice, I finally understood reduce!


Great to hear it @grych !


It was a joke. Bad one, sorry!

Anyway, I like your animation and I am sure it is going to help to understand the functional approach. You might try to add more examples on reduce, like traversing the list of strings with counting the overall number of characters (to show that the reduced value doesn’t have to be the same type as an enumerable member), etc.

Great job!


Love it Daniel :023:

It reminds me of this screencast by Joe Armstrong:

:003: :lol:

1 Like

I’d definitely say add Enum.flat_map if you are wanting to show the basics, it is one of the basic monad operators. :slight_smile:


Also just a quick thought - could you make it so that it takes a copy and works on (or makes obvious it’s) the copy? At the moment anyone new might thing it is altering the starting data, rather than returning a copy :slight_smile:

Thanks for the comments !

I’ve been thinking about how to make the list in the animation appear immutable but I don’t have a solution for it yet. Do you have any suggestions on how to do it Aston ?

1 Like

At the beginning I was thinking of doing: map, reduce & filter because are the most common HOF.
Filter is a bit more difficult to represent visually because it uses an if statement.

flat_map would be also cool with examples from different Monads.

Filter can be done by reduce as well. :slight_smile:

Also map can be done with reduce :slight_smile:

1 Like