Skip to main content
3 of 3
Commonmark migration

Swift

Swift allows for custom operators, this one still lets any other two numbers be added as you'd expect but if both arguments are 2 it will return 5.

func +(l:Int, r:Int) -> Int {
    var a = -r - l
    if l == 2 && r == 2 {--a}
    return -a 
}

print(2+2)