[swift-evolution] [Pitch] Replace the ternary operator with an in-language function

Anton Zhilin antonyzhilin at gmail.com
Wed Oct 26 04:35:35 CDT 2016


infix operator ♠️ : LogicalDisjunctionPrecedenceinfix operator ♥ :
LogicalDisjunctionPrecedence
func ♠️<T>(lhs: Bool, rhs: @autoclosure () throws -> T) rethrows -> T? {
    if lhs { return rhs() } else { return nil }
}func ♥<T>(lhs: T?, rhs: @autoclosure () throws -> T) rethrows -> T {
    return lhs ?? rhs
}
// Equivalent statements:
condition() ? first() : second()
condition() ♠️ first() ♥ second()

By removal of ?:, we could simplify our system of operators and prevent
some ternary-related bugs/unexpected stuff. We could modify reserved
operators to allow ? instead of ♠️ and : instead of ♥.
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161026/6be45571/attachment.html>


More information about the swift-evolution mailing list