Created
October 4, 2016 15:31
-
-
Save jeremytregunna/8858c5d1c597a0baf7cfbfe2390ac5a3 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
| protocol StateType {} | |
| func withTypes<SpecificState>(_ state genericState: StateType?, function: (_ state: SpecificState?) -> SpecificState) -> StateType { | |
| guard let genericState = genericState else { | |
| return function(nil) as! StateType | |
| } | |
| guard let specificState = genericState as? SpecificState else { | |
| return genericState | |
| } | |
| return function(specificState) as! StateType | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment