Instantly share code, notes, and snippets.

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