Not too long ago Iain Delaney pointed me to this graphic:
It wasn’t written in Swift and certainly wasn’t running in Swift. I decided to play around: I built a playground, assigning massive lists of emoji strings to emoji variables, and got these examples running properly using Swift syntax.
Rather than use a pile of poo, which assumes at each stage of reduction you’re combining poo with a new food, I went with Jaden Geller’s recommendation on Twitter. In the Swift version, the reduction starts with a sad face and becomes happy and satisfied.
I played around with other foods to see if it was worth expanding the samples but it was never quite as clean or elegant as the simple 4-item original:
Stepping away from the cow/potato/chicken/corn space, I wanted to see if there might be a better filter than
isVegetarian. A child makes amusing (if not nutritious) food choices:
And then I thought, well what about other Swift language essentials. So I mocked up the concept of naming items by whether they are mutating or non-mutating:
And sorted (although this one could probably use some better food choices):
Zipping was an obvious win as well:
And map vs flatMap:
Unfortunately, a soccer ball is not a valid character identifier so I couldn’t bitcast between a European football and an America one. Inconsistent Emoji character sets made me sad. Swift needs a standards-based operator and identifier makeover:
By the time I started playing with
fatalError, I realized I was spending way too much time on this:
Do you have any favorite Swift functionality that lends itself to emojification? I’ve showed you mine. Now, show me yours.
Update: Phil Aaronson suggests using emoji functions too.
— Phil Aaronson (@phildrone) November 8, 2016
Ideally, examples should be able to compile and run in a Swift playground but I’m open to concepts that can be better explained with Emoji even when implementation is tricky.