Hi Swift community,
I’d love to discuss with you the future of tuples in Swift. I’m really curious
whether tuples will ever evolve beyond their current state or not.
Last year we revamped custom operators with a whole new syntax in Swift, so why
don’t we start a discussion on how tuples could evolve to enhance the language.
Currently tuples are a fixed and ordered set of types, which has only one
syntactic sugar feature to provide a better way of accessing the stored vales.
I was referring to labeled tuples. And that’s pretty much it what tuples
provides for us up until now. Tuple is a primitive type, but so are structs,
enums, string, character and number types in different languages. In Swift we
have way more powerful primitive types, but we’d like to call them value types
instead.
Could we make tuples as *extensible* value types?
Can we vectorize tuples with fixed and unbound length of types? Speaking of
which, variadics share a similar fashion of providing an unbound ordered set of
types, which could be more generalized with tuples. Beyond that, vectorized
tuples could probably play well with generic variadics, and we also would have
the ability to limit the number of types with tuple related constraints.
If a tuple contains a specific, ordered set of types we could probably make it
conditional conforming to protocols like Sequence or Collection to easily
convert it to an array or any other type that accepts such existential.
The following snippet is not a design of *new* tuples nor something I’d propose
at this moment, but a simple sketch to memorize what we could do to tuples.
However I’m not proposing to change the current syntax for tuples, lets call it
_shorthand-syntax_ (label1: Int, String), but I’d like to open the door for an
additional more flexible way to create tuples.
typealias MyTuple<T> = tuple {
T,
Int,
vector String, // same as `String…`
vector(10) Bool // fixed length of 10 booleans
}
typealias MyTuple<T> = (T, Int, vector String, vector(10) Bool)
extension MyTuple : MyProtocol { ... }
Your feedback and ideas of the future of tuples is much appreciated.
--
Adrian Zubarev
Sent with Airmail
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution