Last active
February 28, 2020 03:58
-
-
Save Qata/6f81db9bfd524221e4cb4c1d412c9ad3 to your computer and use it in GitHub Desktop.
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
public extension Bool { | |
func `if`<T>(true truth: @autoclosure () -> T, false falsity: @autoclosure () -> T) -> T { | |
switch self { | |
case true: | |
return truth() | |
case false: | |
return falsity() | |
} | |
} | |
func `if`<T>(true value: @autoclosure () -> T?) -> T? { | |
switch self { | |
case true: | |
return value() | |
case false: | |
return nil | |
} | |
} | |
func `if`<T>(false value: @autoclosure () -> T?) -> T? { | |
switch self { | |
case true: | |
return nil | |
case false: | |
return value() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment