Skip to content

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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.