Created
September 13, 2017 20:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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