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

plx plxswift at icloud.com
Tue Dec 8 10:00:26 CST 2015


FWIW, the possibility of tuple-punning (tuple -> function arguments) provides a lot of practical uses for larger tuples, but these aren’t actually uses that would really benefit from having `==`, etc., defined.

What *would* be useful for those uses is some standard way to flatten “nested" tuples -> “flat" tuples — `((a,b),(c,d),(e,f,g)) -> (a,b,c,d,e,f,g)` and so on — if it doesn’t already exist (does it?).

> On Dec 7, 2015, at 5:01 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> 
> On Dec 7, 2015, at 12:01 PM, Dmitri Gribenko via swift-evolution <swift-evolution at swift.org <mailto: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
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list