Instantly share code, notes, and snippets.

Embed
What would you like to do?
infix operator !=> { associativity left precedence 125 }
func !=><T>(lhs: T?, @noescape rhs: () -> Void) -> T? {
if let lhs = lhs { return lhs }
rhs()
return nil
}
let string: String? = "test"
let nilString: String? = nil
if let str1 = string !=> { print("String 1 is nil") },
let str2 = nilString !=> { print("String 2 is nil") } {
print("All optionals are unwrapped")
}
// Output: String 2 is nil
func !=><T: BooleanType>(lhs: T, @noescape rhs: () -> Void) -> Bool {
if lhs { return true }
rhs()
return false
}
func !=><T>(lhs: T?, @autoclosure rhs: () -> Void) -> T? {
return lhs !=> { rhs() }
}
func !=><T: BooleanType>(lhs: T, @autoclosure rhs: () -> Void) -> Bool {
return lhs !=> { rhs() }
}
if let httpResponse = response as? NSHTTPURLResponse
!=> failure(Reason.Other(error), data)
where httpResponse.statusCode == 200
!=> print("Error: \(httpResponse.statusCode)")
!=> failure(Reason.NoSuccessStatusCode(statusCode: httpResponse.statusCode), data),
let responseData = data
!=> failure(Reason.NoData, data),
let result = resource.parse(responseData)
!=> failure(Reason.CouldNotParseJSON, data) {
completion(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment