Swift/Foundation: Inconsistent > and < operators of Measurement

Viewed 37

Foundation.Measurement implements > and < operators with these signatures:

static func > (
    lhs: Measurement<UnitType>,
    rhs: Measurement<UnitType>
) -> Bool

(https://developer.apple.com/documentation/foundation/measurement/2883205)

static func < <LeftHandSideType, RightHandSideType>(
    lhs: Measurement<LeftHandSideType>,
    rhs: Measurement<RightHandSideType>
) -> Bool where LeftHandSideType: Unit, RightHandSideType: Unit

(https://developer.apple.com/documentation/foundation/measurement/2293618)

Why would they differ?

It seems like they didn’t bother implementing >:

This is the default implementation of the greater-than operator (>) for any type that conforms to Comparable.

It seems they went ahead and just implemented <, not >–using a different signature.

Why does the < operator allow different unit types for lhs and rhs? Who would want to compare apples and oranges? I would expect:

static func < (
    lhs: Measurement<UnitType>,
    rhs: Measurement<UnitType>
) -> Bool
0 Answers
Related