Created
December 13, 2016 07:13
-
-
Save trilliwon/3fe5db4c1e0c6ec47d822e635d6e8947 to your computer and use it in GitHub Desktop.
custom operators in swift
This file contains 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 ??? | |
infix operator ?-> | |
// user.name ??? sendMessage() | |
// is euqual to | |
// if let name = user.name { | |
// sendMessage() | |
// } | |
public func ???<T>(optional: T?, defaultClosure: @autoclosure () -> () ){ | |
if optional != nil { | |
defaultClosure() | |
} | |
} | |
// isAuthenticatedUser ?-> sendMessage() | |
// is euqal to | |
// if isAuthenticatedUser { | |
// sendMessage() | |
// } | |
public func ?-> (lhs: Bool, rhs: @autoclosure () -> ()) { | |
if lhs { rhs() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment