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

Dmitri Gribenko gribozavr at gmail.com
Mon Dec 7 18:13:10 CST 2015


On Mon, Dec 7, 2015 at 4:12 PM, Kevin Ballard via swift-evolution
<swift-evolution at swift.org> wrote:
> On Mon, Dec 7, 2015, at 04:11 PM, Brent Royal-Gordon via swift-evolution
> wrote:
>> > you can implement its < operator as simply "return (a1,b1,c1,d1,e1) < (a2,b2,c2,d2,e2)”.
>>
>>       return zip([a1,b1,c1,d1,e1], [a2,b2,c2,d2,e2]).lazy.filter(==).first.flatMap(<) ?? false
>>
>> Okay, so that wasn’t quite as easy as I thought when I started writing
>> the email.
>
> That also allocates two intermediate arrays (the inputs to zip()).

And relies on all variables having the same type.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list