[swift-evolution] CollectionType on uniform tuples [forked off Contiguous Variables]
Brent Royal-Gordon
brent at architechies.com
Fri Feb 12 15:37:34 CST 2016
> How realistic is it to also have a `count` getter? If we can't have `for elem in tuple`, at least that would allow `for i in 0..<tuple.count`.
I do want a way to get the count (or you could call it the arity, doesn't really matter). The syntax is a bit of an issue, though. Four suggestions, each annotated with its flaw:
typealias FourInts = (4 x Int)
let fourInts = (1, 2, 3, 4)
fourInts.arity // might interfere with tuples that have an element labeled `arity`
FourInts.arity // didn't someone say SIL has trouble with things like properties on compound types?
arity(FourInts) // this is known at compile time, no need for a runtime function call
#arity(FourInts) // hash is kind of gross, and I'm currently suspicious of all hash proposals
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list