Explaining map & reduce with animated examples

functional-programming
maps
reduce
#1

Hi! I created some animations to explain what happens internally with map & reduce functions.
The code is open source. Any feedback is welcome !
https://lambdabricks.github.io/animating-hofs/

10 Likes

#2

Heh, that’s cool looking.

1 Like

#3

Thanks @OvermindDL1!

1 Like

#4

Nice, I finally understood reduce!

4 Likes

#5

Great to hear it @grych !

2 Likes

#6

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!

3 Likes

#7

Love it Daniel :023:

It reminds me of this screencast by Joe Armstrong:

:003: :lol:

1 Like

#8

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:

2 Likes

#9

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:

0 Likes

#10

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

#11

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.

0 Likes

#12

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

0 Likes

#13

Also map can be done with reduce :slight_smile:

1 Like