# [swift-evolution] Fwd: [Proposal][Discussion] Deprecate Tuple Shuffles

André Videla andre.videla at gmail.com
Mon May 8 03:36:20 CDT 2017

```I just realized this message was not sent to evolution

---------- Forwarded message ----------
From: André Videla <andre.videla at gmail.com>
Date: 2017-05-08 9:51 GMT+02:00
Subject: Re: [swift-evolution] [Proposal][Discussion] Deprecate Tuple
Shuffles
To: Xiaodi Wu <xiaodi.wu at gmail.com>

Let me show you:

assume we have this data type which is just a pair of Ints

enum Pair {

case point(x: Int, y: Int)

}

and see how Swift allows us to deconstruct it:

if case .point(let x, let y) = Pair.point(x: 3, y: 5) {

print("\(x), \(y)")

}

this is perfectly fine. Even if the labels are omitted the structure is
kept and x = 3 and y = 5

if case .point(x: let x, y: let y) = Pair.point(x: 3, y: 5) {

print("\(x), \(y)")

}

perfectly fine, x and y are given and correspond to the actual label of the
enum case x = 3, y = 5

if case .point(y: let x, x: let y) = Pair.point(x: 3, y: 5) {

print("\(x), \(y)")

}

This is an error, as expected, labels do not correspond to any existing
known structure and the match makes no sense. It does not compile

Now we refactor the code a bit and we start using a pair instead of an enum
case

if case (let x, let y) = (x: 3, y: 5) {

print("\(x), \(y)")

}

this is fine since the structure is preserved from the value on the right,
x = 3, y = 5

if case (x: let x, y: let y) = (x: 3, y: 5) {

print("\(x), \(y)")

}

this is fine since the labels correspond to the existing structure on the
right x = 3, y = 5

if case (y: let x, x: let y) = (x: 3, y: 5) {

print("\(x), \(y)")

}

And this.

This compiles even though the *structure matched does not correspond to the
structure of the value against which it matches*.  x = 5, y = 3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170508/7a033898/attachment.html>
```