Skip to content

Instantly share code, notes, and snippets.

@djtech42
Created June 9, 2017 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djtech42/bcf4eec4f4998fadb154939bfce6a374 to your computer and use it in GitHub Desktop.
Save djtech42/bcf4eec4f4998fadb154939bfce6a374 to your computer and use it in GitHub Desktop.
When/Else { } block from Kotlin in Swift
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