Last active
March 19, 2018 22:00
-
-
Save dpgao/799521f251119ce8bbdf832a1ca1dbb8 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 !=> { associativity left precedence 125 } | |
| func !=><T>(lhs: T?, @noescape rhs: () -> Void) -> T? { | |
| if let lhs = lhs { return lhs } | |
| rhs() | |
| return nil | |
| } |
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
| 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 |
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
| func !=><T: BooleanType>(lhs: T, @noescape rhs: () -> Void) -> Bool { | |
| if lhs { return true } | |
| rhs() | |
| return false | |
| } |
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
| func !=><T>(lhs: T?, @autoclosure rhs: () -> Void) -> T? { | |
| return lhs !=> { rhs() } | |
| } | |
| func !=><T: BooleanType>(lhs: T, @autoclosure rhs: () -> Void) -> Bool { | |
| return lhs !=> { rhs() } | |
| } |
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
| 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