Categories
Uncategorized

Demonstrating map, filter, and reduce in Swift using food emoji

In my last article, I posted this graphic, which uses emoji to make it easier to understand what the map, filter, and reduce functions do:

map filter reduce in emoji

Since then, I’ve been asked by a couple of friends if what’s in the graphic is just pseudocode or if it could actually be implemented. I told them it was the latter, and here’s my implementation in Swift:

I put this into a Swift playground, which you can copy from this Gist or download here.

2 replies on “Demonstrating map, filter, and reduce in Swift using food emoji”

Leave a Reply

Your email address will not be published. Required fields are marked *