[swift-evolution] Proposal: Implement == and < for tuples where possible, up to some high arity

Chris Lattner clattner at apple.com
Mon Dec 7 17:01:20 CST 2015


On Dec 7, 2015, at 12:01 PM, Dmitri Gribenko via swift-evolution <swift-evolution at swift.org> wrote:
> func > <A: Comparable, B: Comparable, C: Comparable>(lhs: (A, B, C), rhs: (A, B, C)) -> Bool {
>     if lhs.0 != rhs.0 { return lhs.0 > rhs.0 }
>     if lhs.1 != rhs.1 { return lhs.1 > rhs.1 }
>     return lhs.2 > rhs.2
> }
> 
> Looks like a good idea to me!  Also the <= and >= operators, right?

+1 from me too.

> I personally don't see a point in going as high as 12 tuple elements.  About 4 or 5 makes sense to me.  Given that Swift does not have variadic generics right now, these long tuples have to be defined by someone manually.  If one is defining a tuple that is that long, I'd argue that they should be using a custom struct instead.

I tend to agree with Dmitri here.  Independent of the code size concern, what is the expected use-case for > 4 element tuples?

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151207/b292bab5/attachment.html>


More information about the swift-evolution mailing list