Some small tools to make Ranges easier to work with in Swift.
So far, this is the only feature of this package: some protocols to genericize ranges.
In Swift's standard library, all the range types conform to RangeExpression
. However, this doesn't give you much insight: All it guarantees is that the range's bounds are comparable, that it can contain a value, and that it might be resolved to a Range
within a given collection.
This package adds more protocols. These, for accessing members of a range generically:
RangeProtocol
: A protocol to which all ranges, evenNSRange
, conform. Also includes info on whether that upper bound is inclusive.RangeWithLowerBound
: Any range which has a lower bound, such asa...
,a..<b
, anda...b
RangeWithUpperBound
: Any range which has an upper bound, such as..<b
,...b
,a..<b
, anda...b
RangeWithLowerAndUpperBound
: Any range which has both a lower and an upper bound, such asa..<b
anda...b
And these for creating ranges generically:
RangeWhichCanBeInitializedWithOnlyLowerBound
: Any range which can be initialized only with a lower bound, likea...
RangeWhichCanBeInitializedWithOnlyUpperBound
: Any range which can be initialized only with an upper bound, like..<b
or...b
RangeWhichCanBeInitializedWithBothLowerAndUpperBounds
: Any range which can be initialized with both lower and upper bounds, likea..<b
ora...b