[swift-evolution] Limit checking syntax

Dave Abrahams dabrahams at apple.com
Fri Apr 8 13:21:41 CDT 2016


on Fri Apr 08 2016, "Vladimir.S via swift-evolution" <swift-evolution at swift.org> wrote:

> On 08.04.2016 4:14, Harlan Haskins via swift-evolution wrote:
>> I’ve found that .contains works well for all my uses.
>>
>> (0..<100).contains(x)
>
> Hmm.. Isn't next construction is much more readable?:
>
> x.in(0..<100)

API guidelines prescribe this should read as an assertion about x, so:

     x.isContainedIn(0..<100)

or 

     x.isIn(0..<100)

FWIW.

> I think it is much more readable.
> We are planning(in head) to verify "if x value is in range from 0 up
> to 99", so why we have to write "for some range 0 to 9 let's check if
> it contains our x value".
> Our x is a subject of our check, not range (0..<100).
>
> I.e. in my opinion -1 for 'in' operator like suggested in initial message,
> but +1 for .in method for integer to check against range
> Any additional opinion?
>
> Vladimir
> (P.S. Sorry for duplicate.)
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-- 
Dave



More information about the swift-evolution mailing list