Skip to content

Releases: RougeWare/Swift-Range-Tools

1.2 - `upperBoundIsInclusive`

08 Jun 23:05
8efcac7
Compare
Choose a tag to compare

This provides static info on whether that upper bound is inclusive. It will betrue iff the upper bound of this protocol includes the element at its index, like ...b and a...b. false indicates that the upper bound does not include that element, like ..<b and a..<b.


1.2.1

This patch allows all ranges to specify whether their upper bound is inclusive; in 1.2.0, upperBoundIsInclusive was only available on RangeWithUpperBound.

Even when an upper bound isn't explicitly specified, it's still good to acknowledge whether it's inclusive, so we know that things like myArray = [0,1,2] can return [] validly when accessed like myArray[3...].

We might imagine that, given a hypothetical a..< range, myArray[3..<] would not validly return []:

let myArray = [0, 1, 2]
myArray[0...] == [0, 1, 2]
myArray[1...] == [   1, 2]
myArray[2...] == [      2]
myArray[3...] == [       ]

myArray[0..<] == [0, 1]
myArray[1..<] == [   1]
myArray[2..<] == [    ]
myArray[3..<] == invalid!

So, even if the range doesn't specify its upper bound, we can still gain useful knowledge by understanding whether the upper end of it is inclusive

1.1 - Initialization protocols

08 Jun 18:37
0b3bc35
Compare
Choose a tag to compare

This adds some more protocols to improve generic usage of ranges:

  • RangeWhichCanBeInitializedWithOnlyLowerBound: Any range which can be initialized only with a lower bound, like a...
  • 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, like a..<b or a...b

1.0 - MVP

08 Jun 17:06
145a9e2
Compare
Choose a tag to compare

Kicking this off with a few protocols to help make it easier to use Ranges! See the Readme for more info