Thor
Thor

Reputation: 10058

clarification on the function declaration of ..<

I'm currently learning the range operator ..< in swift. I understand how ..< works on the surface, but what I really want to know is how ..< works in a bit more detail.

Below is a copy of the ..< function declaration. I have found apple documentation on Comparable, CountableRange, but have not been able to find any documentation on Bound, _Strideable, Bound.Stride. So could someone please tell me how I can find out more about those classes? Or if it is not possible to find documentations on those classes, could you please explain what they actually does?

for index in 0..<2 {
    print(index)
}

enter image description here

func ..<<Bound where Bound : _Strideable & Comparable, Bound.Stride : Integer>(minimum: Bound, maximum: Bound) -> CountableRange<Bound>

Upvotes: 0

Views: 48

Answers (1)

David Berry
David Berry

Reputation: 41236

This:

func ..<<Bound where Bound : _Strideable & Comparable, Bound.Stride : Integer>(minimum: Bound, maximum: Bound) -> CountableRange<Bound>

defines a generic function ..< which uses Bound as the placeholder type and places some restrictions on that placeholder type. Specifically Bound must be both _Strideable and Comparable and Bound.Stride (which is an associated type defined in _Strideable) must be Integer

So... it defines a function ..< which takes two arguments of the same type which must be strideable and comparable and the stride associated type must be Integer

Upvotes: 1

Related Questions