# \[Proposal\] Invert the order of pattern match operator

**URL:** <https://forums.swift.org/t/proposal-invert-the-order-of-pattern-match-operator/2090>\
**Category:** Discussion\
**Created:** [April 7, 2016, 11:57am UTC](https://forums.swift.org/t/proposal-invert-the-order-of-pattern-match-operator/2090 "2016-04-07T11:57:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Rodrigues](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/david_rodrigues/32/7604_2.png) [@David\_Rodrigues](https://forums.swift.org/u/David_Rodrigues)\
**Post date:** [April 7, 2016, 11:57am UTC](https://forums.swift.org/t/proposal-invert-the-order-of-pattern-match-operator/2090/1 "2016-04-07T11:57:53Z")

</div>

Hi all,

Swift has a pattern match operator, ~=, which is unknown to many (like me  
until a few weeks ago), that performs a match between a value and a certain  
pattern, e.g. checking if an integer value is contained in a range of  
integers.

This operator may be little known, but it plays a key role in the language  
since it's used behind the scenes to support expression patterns in  
`switch` statement case labels, which we all know are extremely popular.

let point = (2, 4)  
switch point {  
case (0, 0):  
&nbsp;&nbsp;&nbsp;&nbsp;print("The point is at the origin")  
case (0...4, 0...4):  
&nbsp;&nbsp;&nbsp;&nbsp;print("The point is in the subregion")  
default:  
&nbsp;&nbsp;&nbsp;&nbsp;break  
}

Most of the time we don't use the operator directly but it is available and  
can be handy in certain conditions.

let point = (2, 4)  
switch point {  
case (let x, let y) where 0...4 ~= x && 0...4 ~= y:  
&nbsp;&nbsp;&nbsp;&nbsp;print("The point is in the subregion")  
default:  
&nbsp;&nbsp;&nbsp;&nbsp;break  
}

However the current syntax is not ideal (in my opinion). We're not really  
declaring the operation that we want to do, and that has an impact in the  
expressivity and readability of the code. Currently we're doing matches  
like "if blue is the ocean" instead of "if the ocean is blue" or "if the  
ocean contains the whale" instead of "if the whale is in the ocean".

For that reason, I would like to suggest inverting the order of the  
operator to match more closely our logical thought.

case (let x, let y) where x =~ 0...4 && y =~ 0...4: // Proposed  
// vs  
case (let x, let y) where 0...4 ~= x && 0...4 ~= y: // Current

I have an ongoing proposal to suggest this change and it contains a little  
more context. It is available here:

> <https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md>

.

Any feedback is very welcome.

Thank you.

David Rodrigues

---

<div class="post-metadata">

**Author:** ![owensd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/owensd/32/8934_2.png) [@owensd](https://forums.swift.org/u/owensd)\
**Post date:** [April 7, 2016, 5:09pm UTC](https://forums.swift.org/t/proposal-invert-the-order-of-pattern-match-operator/2090/2 "2016-04-07T17:09:55Z")

</div>

It would be nice to know the rationale behind the choice of the current syntax. I agree that these seem more natural:

@warn\_unused\_result  
public func ~=\<I : ForwardIndexType where I : Comparable\>(value: I, pattern: Range\<I\>) -\> Bool

@warn\_unused\_result  
public func ~=\<I : IntervalType\>(value: I.Bound, pattern: I) -\> Bool

I would not change from `~=` to `=~` though.

So you have this:

let x = 4

switch x {  
case let v where x ~= 0...5: print("matched: \(v)")  
default: print("nothing!!")  
}

-David

> **···**
>
> > On Apr 7, 2016, at 4:57 AM, David Rodrigues via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > Hi all,
> > 
> > Swift has a pattern match operator, ~=, which is unknown to many (like me until a few weeks ago), that performs a match between a value and a certain pattern, e.g. checking if an integer value is contained in a range of integers.
> > 
> > This operator may be little known, but it plays a key role in the language since it's used behind the scenes to support expression patterns in `switch` statement case labels, which we all know are extremely popular.
> > 
> > let point = (2, 4)  
> > switch point {  
> > case (0, 0):  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is at the origin")  
> > case (0...4, 0...4):  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is in the subregion")  
> > default:  
> > &nbsp;&nbsp;&nbsp;&nbsp;break  
> > }
> > 
> > Most of the time we don't use the operator directly but it is available and can be handy in certain conditions.
> > 
> > let point = (2, 4)  
> > switch point {  
> > case (let x, let y) where 0...4 ~= x && 0...4 ~= y:  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is in the subregion")  
> > default:  
> > &nbsp;&nbsp;&nbsp;&nbsp;break  
> > }
> > 
> > However the current syntax is not ideal (in my opinion). We're not really declaring the operation that we want to do, and that has an impact in the expressivity and readability of the code. Currently we're doing matches like "if blue is the ocean" instead of "if the ocean is blue" or "if the ocean contains the whale" instead of "if the whale is in the ocean".
> > 
> > For that reason, I would like to suggest inverting the order of the operator to match more closely our logical thought.
> > 
> > case (let x, let y) where x =~ 0...4 && y =~ 0...4: // Proposed  
> > // vs  
> > case (let x, let y) where 0...4 ~= x && 0...4 ~= y: // Current
> > 
> > I have an ongoing proposal to suggest this change and it contains a little more context. It is available here:
> > 
> > [https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md\](https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md%5C).
> > 
> > Any feedback is very welcome.
> > 
> > Thank you.
> > 
> > David Rodrigues  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![dabrahams](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dabrahams/32/9815_2.png) [@dabrahams](https://forums.swift.org/u/dabrahams)\
**Post date:** [April 7, 2016, 6:16pm UTC](https://forums.swift.org/t/proposal-invert-the-order-of-pattern-match-operator/2090/3 "2016-04-07T18:16:00Z")

</div>

> It would be nice to know the rationale behind the choice of the current syntax.  
> I agree that these seem more natural:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;@warn\_unused\_result  
> &nbsp;&nbsp;&nbsp;&nbsp;public func ~=\<I : ForwardIndexType where I : Comparable\>(value: I, pattern:  
> &nbsp;&nbsp;&nbsp;&nbsp;Range\<I\>) -\> Bool
> 
> &nbsp;&nbsp;&nbsp;&nbsp;@warn\_unused\_result  
> &nbsp;&nbsp;&nbsp;&nbsp;public func ~=\<I : IntervalType\>(value: I.Bound, pattern: I) -\> Bool

+1

> I would not change from `~=` to `=~` though.

One downside with `~=` is that it reads like `+=`, which mutates the  
LHS. Of course, `=~` has its own issues, e.g. `x=~y` might read as `x =  
~y`.

> **···**
>
> on Thu Apr 07 2016, David Owens II \<swift-evolution@swift.org\> wrote:
> 
> > So you have this:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;let x = 4
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;switch x {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case let v where x ~= 0...5: print("matched: \(v)")  
> > &nbsp;&nbsp;&nbsp;&nbsp;default: print("nothing!!")  
> > &nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > -David
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;On Apr 7, 2016, at 4:57 AM, David Rodrigues via swift-evolution \> \<swift-evolution@swift.org\> wrote:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;Hi all,
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;Swift has a pattern match operator, ~=, which is unknown to many (like me  
> > &nbsp;&nbsp;&nbsp;&nbsp;until a few weeks ago), that performs a match between a value and a certain  
> > &nbsp;&nbsp;&nbsp;&nbsp;pattern, e.g. checking if an integer value is contained in a range of  
> > &nbsp;&nbsp;&nbsp;&nbsp;integers.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;This operator may be little known, but it plays a key role in the language  
> > &nbsp;&nbsp;&nbsp;&nbsp;since it's used behind the scenes to support expression patterns in `switch  
> > &nbsp;&nbsp;&nbsp;&nbsp;` statement case labels, which we all know are extremely popular.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;let point = (2, 4)  
> > &nbsp;&nbsp;&nbsp;&nbsp;switch point {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case (0, 0):  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is at the origin")  
> > &nbsp;&nbsp;&nbsp;&nbsp;case (0...4, 0...4):  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is in the subregion")  
> > &nbsp;&nbsp;&nbsp;&nbsp;default:  
> > &nbsp;&nbsp;&nbsp;&nbsp;break  
> > &nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;Most of the time we don't use the operator directly but it is available and  
> > &nbsp;&nbsp;&nbsp;&nbsp;can be handy in certain conditions.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;let point = (2, 4)  
> > &nbsp;&nbsp;&nbsp;&nbsp;switch point {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case (let x, let y) where 0...4 ~= x && 0...4 ~= y:  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is in the subregion")  
> > &nbsp;&nbsp;&nbsp;&nbsp;default:  
> > &nbsp;&nbsp;&nbsp;&nbsp;break  
> > &nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;However the current syntax is not ideal (in my opinion). We're not really  
> > &nbsp;&nbsp;&nbsp;&nbsp;declaring the operation that we want to do, and that has an impact in the  
> > &nbsp;&nbsp;&nbsp;&nbsp;expressivity and readability of the code. Currently we're doing matches like  
> > &nbsp;&nbsp;&nbsp;&nbsp;"if blue is the ocean" instead of "if the ocean is blue" or "if the ocean  
> > &nbsp;&nbsp;&nbsp;&nbsp;contains the whale" instead of "if the whale is in the ocean".
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;For that reason, I would like to suggest inverting the order of the operator  
> > &nbsp;&nbsp;&nbsp;&nbsp;to match more closely our logical thought.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;case (let x, let y) where x =~ 0...4 && y =~ 0...4: // Proposed  
> > &nbsp;&nbsp;&nbsp;&nbsp;// vs  
> > &nbsp;&nbsp;&nbsp;&nbsp;case (let x, let y) where 0...4 ~= x && 0...4 ~= y: // Current
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;I have an ongoing proposal to suggest this change and it contains a little  
> > &nbsp;&nbsp;&nbsp;&nbsp;more context. It is available here:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;[https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md](https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md)  
> > &nbsp;&nbsp;&nbsp;.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;Any feedback is very welcome.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;Thank you.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;David Rodrigues  
> > &nbsp;&nbsp;&nbsp;&nbsp;\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > &nbsp;&nbsp;&nbsp;&nbsp;swift-evolution mailing list  
> > &nbsp;&nbsp;&nbsp;&nbsp;swift-evolution@swift.org  
> > &nbsp;&nbsp;&nbsp;&nbsp;[https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
> 
> --  
> Dave

---

<div class="post-metadata">

**Author:** ![Erica\_Sadun](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/erica_sadun/32/243_2.png) [@Erica\_Sadun](https://forums.swift.org/u/Erica_Sadun)\
**Post date:** [April 7, 2016, 5:56pm UTC](https://forums.swift.org/t/proposal-invert-the-order-of-pattern-match-operator/2090/4 "2016-04-07T17:56:38Z")

</div>

I'd prefer to offer both ~= and =~, allowing the consumer to choose which side the pattern sits on.

-- E

> **···**
>
> > On Apr 7, 2016, at 11:09 AM, David Owens II via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > It would be nice to know the rationale behind the choice of the current syntax. I agree that these seem more natural:
> > 
> > @warn\_unused\_result  
> > public func ~=\<I : ForwardIndexType where I : Comparable\>(value: I, pattern: Range\<I\>) -\> Bool
> > 
> > @warn\_unused\_result  
> > public func ~=\<I : IntervalType\>(value: I.Bound, pattern: I) -\> Bool
> > 
> > I would not change from `~=` to `=~` though.
> > 
> > So you have this:
> > 
> > let x = 4
> > 
> > switch x {  
> > case let v where x ~= 0...5: print("matched: \(v)")  
> > default: print("nothing!!")  
> > }
> > 
> > -David
> > 
> > > On Apr 7, 2016, at 4:57 AM, David Rodrigues via swift-evolution \<swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>\> wrote:
> > > 
> > > Hi all,
> > > 
> > > Swift has a pattern match operator, ~=, which is unknown to many (like me until a few weeks ago), that performs a match between a value and a certain pattern, e.g. checking if an integer value is contained in a range of integers.
> > > 
> > > This operator may be little known, but it plays a key role in the language since it's used behind the scenes to support expression patterns in `switch` statement case labels, which we all know are extremely popular.
> > > 
> > > let point = (2, 4)  
> > > switch point {  
> > > case (0, 0):  
> > > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is at the origin")  
> > > case (0...4, 0...4):  
> > > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is in the subregion")  
> > > default:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break  
> > > }
> > > 
> > > Most of the time we don't use the operator directly but it is available and can be handy in certain conditions.
> > > 
> > > let point = (2, 4)  
> > > switch point {  
> > > case (let x, let y) where 0...4 ~= x && 0...4 ~= y:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is in the subregion")  
> > > default:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break  
> > > }
> > > 
> > > However the current syntax is not ideal (in my opinion). We're not really declaring the operation that we want to do, and that has an impact in the expressivity and readability of the code. Currently we're doing matches like "if blue is the ocean" instead of "if the ocean is blue" or "if the ocean contains the whale" instead of "if the whale is in the ocean".
> > > 
> > > For that reason, I would like to suggest inverting the order of the operator to match more closely our logical thought.
> > > 
> > > case (let x, let y) where x =~ 0...4 && y =~ 0...4: // Proposed  
> > > // vs  
> > > case (let x, let y) where 0...4 ~= x && 0...4 ~= y: // Current
> > > 
> > > I have an ongoing proposal to suggest this change and it contains a little more context. It is available here:
> > > 
> > > [https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md\](https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md%5C).
> > > 
> > > Any feedback is very welcome.
> > > 
> > > Thank you.
> > > 
> > > David Rodrigues  
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > swift-evolution mailing list  
> > > swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>  
> > > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![David\_Rodrigues](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/david_rodrigues/32/7604_2.png) [@David\_Rodrigues](https://forums.swift.org/u/David_Rodrigues)\
**Post date:** [April 7, 2016, 7:11pm UTC](https://forums.swift.org/t/proposal-invert-the-order-of-pattern-match-operator/2090/5 "2016-04-07T19:11:28Z")

</div>

> > It would be nice to know the rationale behind the choice of the current syntax.  
> > I agree that these seem more natural:
> > 
> > &nbsp;&nbsp;&nbsp;@warn\_unused\_result  
> > &nbsp;&nbsp;&nbsp;public func ~=\<I : ForwardIndexType where I : Comparable\>(value: I, pattern:  
> > &nbsp;&nbsp;&nbsp;Range\<I\>) -\> Bool
> > 
> > &nbsp;&nbsp;&nbsp;@warn\_unused\_result  
> > &nbsp;&nbsp;&nbsp;public func ~=\<I : IntervalType\>(value: I.Bound, pattern: I) -\> Bool
> 
> +1

This operator was firstly introduced in Swift in the form =~ but then it was reversed to the current form (~3y ago). There’s a little context about this change on Twitter: [https://twitter.com/dmcrodrigues/status/717063623957471232\](https://twitter.com/dmcrodrigues/status/717063623957471232%5C).

> > I would not change from `~=` to `=~` though.
> 
> One downside with `~=` is that it reads like `+=`, which mutates the  
> LHS. Of course, `=~` has its own issues, e.g. `x=~y` might read as `x =  
> ~y`.

I agree but this operator already exists in other languages like Ruby and Perl, so align the syntax may be a good option.

> **···**
>
> > On 07 Apr 2016, at 19:16, Dave Abrahams via swift-evolution \<swift-evolution@swift.org\> wrote:
> 
> > On 07 Apr 2016, at 18:56, Erica Sadun \<erica@ericasadun.com\> wrote:
> > 
> > I'd prefer to offer both ~= and =~, allowing the consumer to choose which side the pattern sits on.
> 
> On the other hand, I like in particular the option of having both `~=` and `=~` to provide more flexibility like Erica has suggested. The main question is if that’s ok introduce another operator in the language.
> 
> —  
> David

---

<div class="post-metadata">

**Author:** ![Haravikk3](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@Haravikk3](https://forums.swift.org/u/Haravikk3)\
**Post date:** [April 8, 2016, 10:22am UTC](https://forums.swift.org/t/proposal-invert-the-order-of-pattern-match-operator/2090/6 "2016-04-08T10:22:07Z")

</div>

Can someone fill me in as to how this differs from (0…4).contains(x)?

Personally I don’t like the choice for the operator, and think it’s not very clear, if we can do the same thing with a method then I’d prefer removing the operator to be honest.

> **···**
>
> > On 7 Apr 2016, at 12:57, David Rodrigues via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > Hi all,
> > 
> > Swift has a pattern match operator, ~=, which is unknown to many (like me until a few weeks ago), that performs a match between a value and a certain pattern, e.g. checking if an integer value is contained in a range of integers.
> > 
> > This operator may be little known, but it plays a key role in the language since it's used behind the scenes to support expression patterns in `switch` statement case labels, which we all know are extremely popular.
> > 
> > let point = (2, 4)  
> > switch point {  
> > case (0, 0):  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is at the origin")  
> > case (0...4, 0...4):  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is in the subregion")  
> > default:  
> > &nbsp;&nbsp;&nbsp;&nbsp;break  
> > }
> > 
> > Most of the time we don't use the operator directly but it is available and can be handy in certain conditions.
> > 
> > let point = (2, 4)  
> > switch point {  
> > case (let x, let y) where 0...4 ~= x && 0...4 ~= y:  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("The point is in the subregion")  
> > default:  
> > &nbsp;&nbsp;&nbsp;&nbsp;break  
> > }
> > 
> > However the current syntax is not ideal (in my opinion). We're not really declaring the operation that we want to do, and that has an impact in the expressivity and readability of the code. Currently we're doing matches like "if blue is the ocean" instead of "if the ocean is blue" or "if the ocean contains the whale" instead of "if the whale is in the ocean".
> > 
> > For that reason, I would like to suggest inverting the order of the operator to match more closely our logical thought.
> > 
> > case (let x, let y) where x =~ 0...4 && y =~ 0...4: // Proposed  
> > // vs  
> > case (let x, let y) where 0...4 ~= x && 0...4 ~= y: // Current
> > 
> > I have an ongoing proposal to suggest this change and it contains a little more context. It is available here:
> > 
> > [https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md\](https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md%5C).
> > 
> > Any feedback is very welcome.
> > 
> > Thank you.
> > 
> > David Rodrigues  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![Brent\_Royal-Gordon](https://avatars.discourse-cdn.com/v4/letter/b/53a042/32.png) [@Brent\_Royal-Gordon](https://forums.swift.org/u/Brent_Royal-Gordon)\
**Post date:** [April 8, 2016, 10:32am UTC](https://forums.swift.org/t/proposal-invert-the-order-of-pattern-match-operator/2090/7 "2016-04-08T10:32:22Z")

</div>

> Can someone fill me in as to how this differs from (0…4).contains(x)?
> 
> Personally I don’t like the choice for the operator, and think it’s not very clear, if we can do the same thing with a method then I’d prefer removing the operator to be honest.

~= is the way you customize how a type behaves when it's a pattern in a switch statement. So ~= (\_: Range\<T\>, \_: T) is responsible for making `case 1..\<10` work properly. Removing it would be...unwise.

> **···**
>
> --  
> Brent Royal-Gordon  
> Architechies

---

<div class="post-metadata">

**Author:** ![Haravikk3](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@Haravikk3](https://forums.swift.org/u/Haravikk3)\
**Post date:** [April 8, 2016, 1:34pm UTC](https://forums.swift.org/t/proposal-invert-the-order-of-pattern-match-operator/2090/8 "2016-04-08T13:34:56Z")

</div>

But why not just (1..\<10).contains(x) behind the scenes instead? This could be redefined as a protocol or whatever. It’s just kind of strange as an operator, and as the OP said not especially well known.

> **···**
>
> > On 8 Apr 2016, at 11:32, Brent Royal-Gordon \<brent@architechies.com\> wrote:
> > 
> > > Can someone fill me in as to how this differs from (0…4).contains(x)?
> > > 
> > > Personally I don’t like the choice for the operator, and think it’s not very clear, if we can do the same thing with a method then I’d prefer removing the operator to be honest.
> > 
> > ~= is the way you customize how a type behaves when it's a pattern in a switch statement. So ~= (\_: Range\<T\>, \_: T) is responsible for making `case 1..\<10` work properly. Removing it would be…unwise.
