Last active
August 29, 2015 14:11
-
-
Save ttepasse/bbb47311ca8a5e6f0263 to your computer and use it in GitHub Desktop.
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
class Bookmark {} | |
class WebView {} | |
class Something {} | |
var bookmark : Bookmark? = Bookmark() | |
var webview : WebView? = WebView() | |
var something : Something? = nil | |
infix operator &&! {} | |
func &&! <LeftType, RightType> (lhs: LeftType?, rhs: RightType?) -> (LeftType, RightType)? { | |
if let left: LeftType = lhs { | |
if let right: RightType = rhs { | |
return (left, right) | |
} | |
} | |
return nil | |
} | |
if let (b, w) = bookmark &&! webview { | |
println(true) | |
} | |
// -> true | |
if let (b, s) = bookmark &&! something { | |
println(true) | |
} else { | |
false | |
} | |
// -> false | |
infix operator &&? { associativity left } | |
func &&? <LeftType, RightType> (lhs: LeftType?, rhs: RightType?) -> Bool { | |
if let left: LeftType = lhs { | |
if let right: RightType = rhs { | |
return true | |
} | |
} | |
return false | |
} | |
func &&? <FirstType> (lhs: FirstType?, rhs: @autoclosure () -> Bool) -> Bool { | |
if let left: FirstType = lhs { | |
return rhs() | |
} | |
return false | |
} | |
bookmark &&? webview // -> true | |
bookmark &&? something // -> false | |
bookmark &&? webview &&? webview // -> true | |
bookmark &&? webview &&? something // -> false | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment