Skip to content

Instantly share code, notes, and snippets.

@Qata
Last active February 28, 2020 03:58
Show Gist options
  • Save Qata/6f81db9bfd524221e4cb4c1d412c9ad3 to your computer and use it in GitHub Desktop.
Save Qata/6f81db9bfd524221e4cb4c1d412c9ad3 to your computer and use it in GitHub Desktop.
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