Redeclaration of named tuple members

Tuple shuffling is about reordering labels without changing the overall set of labels. Adding or stripping the labels is a separate feature. Anything that messes with the labels that isn't one of those two operations is probably a bug caused by a bad interaction between the two features.

As far as the as? issue goes, the fix-it is wrong—please file a bug!—but the correct thing to write here is as (Int, Int)?. That is, you want to do a compile-time conversion to an Optional tuple value, as opposed to a run-time-checked conversion to a non-Optional value.

1 Like

Btw, here is a way to get the behavior you ask for in the OP (for any tuple) at the cost of one extra character:

// Make a prefix operator that converts any labeled tuple to an unlabeled one:
prefix operator •
prefix func •<A, B>(rhs: (A, B)) -> (A, B) { return rhs }
prefix func •<A, B, C>(rhs: (A, B, C)) -> (A, B, C) { return rhs }
prefix func •<A, B, C, D>(rhs: (A, B, C, D)) -> (A, B, C, D) { return rhs }
// ... add more if needed ...

// Now you can do this:
func test() {
    let counter = 119
    let final: (min: Int, sec: Int) = •counter.quotientAndRemainder(dividingBy: 60)
    print(final) // (min: 1, sec: 59)
}
test()
1 Like