Created
June 9, 2017 15:08
-
-
Save djtech42/bcf4eec4f4998fadb154939bfce6a374 to your computer and use it in GitHub Desktop.
When/Else { } block from Kotlin in Swift
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 when<T, U>(_ value: T, _ cases: [T:U], else elseCaseValue: U) -> U { | |
if let existingCaseValue = cases[value] { | |
return existingCaseValue | |
} | |
else { | |
return elseCaseValue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment