Reputation: 10058
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)
}
func ..<<Bound where Bound : _Strideable & Comparable, Bound.Stride : Integer>(minimum: Bound, maximum: Bound) -> CountableRange<Bound>
Upvotes: 0
Views: 48
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