Skip to content

Instantly share code, notes, and snippets.

@frederik-jacques
Created September 13, 2017 20:23
Show Gist options
  • Save frederik-jacques/8efb3f0a8cbd46aa760880878a650931 to your computer and use it in GitHub Desktop.
Save frederik-jacques/8efb3f0a8cbd46aa760880878a650931 to your computer and use it in GitHub Desktop.
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