I didn’t add a SuperReallyPeachyKeenProtocol example. It assumes we eventually 
add variadic generics:

retype TupleCollection<T, U…>: (T, …U), RandomAccessCollection allwhere U == T {
export default  // Without this, instances of “self” below would be “super” 
instead.

var head: T {
get { return self.0 }
set { self.0 = newValue }
}
var tail: (…U) {
// Put some cool template meta-programming here, thanks.
}

subscript(index: Int) -> T {
get { return index == 0 ? self.0 : tail[index - 1] }
set {
if index == 0 {
self.0 = newValue
} else {
tail[index - 1] = newValue
}
}
}
//…
}

// Put terminal specialization of TupleCollection<> here.

//…

func myFunc2() {
var myTuple: (Int, Int, Int, Int) = (0, 0, 0, 0)
pose myCollection = myTuple as TupleCollection

for i in myCollection {
i += 2
}
print(myTuple)  // (2, 2, 2, 2)
}

Now you don’t have to permanently add subscripting to tuple types.

[Oh, instead of expanding a parameter pack with U…, I automatically expand it 
with “where” variants where-any and where-all. The first considers each member 
of the pack separately and then applies logical-OR to the result (default to 
FALSE when empty). The second does a logical-AND (defaulting to TRUE when 
empty). The where-any marker could be renamed to “anywhere,” but that would 
need an “allwhere” to be consistent. Turns, out “allwhere” is a word, albeit 
archaic!]

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to