Skip to content

Instantly share code, notes, and snippets.

@frederik-jacques
Created September 13, 2017 20:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Easily map to a value based on the value of a Boolean
import Foundation
extension Bool {
/// Convenience method to map the value of a Boolean to a specific Type.
///
/// - Parameters:
/// - ifTrue: The result when the Boolean is true
/// - ifFalse: The result when the Boolean is false
/// - Returns: Returns the result of a specific Type
func mapTo<T>( ifTrue:T, ifFalse:T ) -> T {
if self {
return ifTrue
} else {
return ifFalse
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment