Add a few lines to your Swift project, start coding with emoji.
Everybody loves emoji, and everybody loves swift. Swift is a powerful but serious language, with emojis, it becomes funnier and cuter than ever.
Before anything ever happens, we define the basic types in swift.
typealias 👍👎 = Bool
//Here we also define 'true' and 'false'
let 👍 = true
let 👎 = false
typealias 🔤 = String
typealias ℹ️🔤 = CustomStringConvertible
typealias 🔢 = Int
typealias 🔢📶 = Double
Once we defined some necessary types, we can create some proxy functions like print
// Here I just used a closure calling the print function
let 🖨 = { (🛄: ℹ️🔤) in print(🛄) }
This is the part where you'll have to use your brain. Here is my version of if-else
//First define a struct so we can implement `else`
struct 🌝🌚{
var 🌚: (() -> ()) -> ()
}
//Then we define the 'if' function
func 🌝(_ 🛄👌: 👍👎, _ 🛄🌝: () -> ()) -> 🌝🌚 {
//Check if condition is true
if(🛄👌){
//If true, call the trailing closure
🛄🌝()
//Return 🌝🌚 with a closure that does nothing
return 🌝🌚(🌚: { _ in })
} else {
//Return 🌝🌚 with a closure that calls the parameter immedietly
return 🌝🌚(🌚: { 🛄 in 🛄() })
}
}
This results in something like:
🌝(👍){ 🖨("yes") }
.🌚{ 🖨("no") }
//prints: 'yes'