Last active
March 29, 2017 17:48
-
-
Save chrisbrandow/7eb91366075f33fb8ec01bacb11454bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
infix operator ??? : TernaryPrecedence | |
infix operator ||| : AdditionPrecedence | |
func ???(input: String?, valuesBlock: ((String?) -> String)) -> String { | |
return valuesBlock(input) | |
} | |
func |||(ifNotNil: String, ifNil: String) -> ((String?) -> String) { | |
return { (input: String?) -> String in | |
if let _ = input { | |
return ifNotNil | |
} else { | |
return ifNil | |
} | |
} | |
} | |
var anotherOptionalValue: String? = nil | |
let notNil = anotherOptionalValue ??? valueIfNotNil ||| valueIfNil | |
print("notNil: \(notNil)") | |
anotherOptionalValue = "string" | |
let yeahItsNil = anotherOptionalValue ??? valueIfNotNil ||| valueIfNil | |
print("yeahItsNil: \(yeahItsNil)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment