[swift-evolution] [Proposal] Invert the order of pattern match operator
Haravikk
swift-evolution at haravikk.me
Fri Apr 8 08:34:56 CDT 2016
> On 8 Apr 2016, at 11:32, Brent Royal-Gordon <brent at 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.
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.
More information about the swift-evolution
mailing list