Proposal: Allow comparisons of arrays possibly containing nil


(Amir Michail) #1

Example:

[Int?]([1,2,nil]) == [Int?]([1,2,nil])

This currently results in: “binary operator '==' cannot be applied to two '[Int?]' operands"


(TJ Usiyan) #2

Does this work for now?

func ==<T : Equatable>(lhs:[T?], rhs: [T?]) -> Bool {
    let zipped = Zip2Sequence(lhs, rhs)

    return zipped.reduce(true) { (old, tuple) in
        old && (tuple.0 == tuple.1)
    }
}

···

On Fri, Jan 1, 2016 at 12:32 PM, Amir Michail via swift-evolution < swift-evolution@swift.org> wrote:

Example:

[Int?]([1,2,nil]) == [Int?]([1,2,nil])

This currently results in: “binary operator '==' cannot be applied to two
'[Int?]' operands"
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution