Skip to content

Commit

Permalink
Merge pull request #4 from RougeWare/feature/upperBoundIsInclusive
Browse files Browse the repository at this point in the history
Added `upperBoundIsInclusive` to `RangeWithUpperBound`
  • Loading branch information
KyNorthstar authored Jun 9, 2021
2 parents c0adde0 + 658cd45 commit 8efcac7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ In Swift's standard library, all the range types conform to `RangeExpression`. H

This package adds more protocols. These, for accessing members of a range generically:

- `RangeProtocol`: A protocol to which all ranges, even `NSRange`, conform
- `RangeProtocol`: A protocol to which all ranges, even `NSRange`, conform. Also includes info on whether that upper bound is inclusive.
- `RangeWithLowerBound`: Any range which has a lower bound, such as `a...`, `a..<b`, and `a...b`
- `RangeWithUpperBound`: Any range which has an upper bound, such as `..<b`, `...b`, `a..<b`, and `a...b`. Also includes info on whether that upper bound is inclusive.
- `RangeWithUpperBound`: Any range which has an upper bound, such as `..<b`, `...b`, `a..<b`, and `a...b`
- `RangeWithLowerAndUpperBound`: Any range which has both a lower and an upper bound, such as `a..<b` and `a...b`

And these for creating ranges generically:
Expand Down
4 changes: 3 additions & 1 deletion Sources/RangeTools/Default conformances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ extension ClosedRange: RangeWithLowerAndUpperBound {



extension PartialRangeFrom: RangeWithLowerBound {}
extension PartialRangeFrom: RangeWithLowerBound {
public static var upperBoundIsInclusive: Bool { true }
}



Expand Down
7 changes: 4 additions & 3 deletions Sources/RangeTools/RangeProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public protocol RangeProtocol {



/// `true` iff the upper bound of this protocol includes the element at its index, like `a...`, `...b`, and `a...b`. `false` indicates that the upper bound does not include that element, like `..<b` and `a..<b`.
static var upperBoundIsInclusive: Bool { get }


/// Determines whether this range contains the given element
///
/// - Parameter element: The element you want to see if this range contains
Expand Down Expand Up @@ -58,9 +62,6 @@ public protocol RangeWithUpperBound: RangeProtocol {

/// The range's upper bound
var upperBound: Bound { get }

/// `true` 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`.
static var upperBoundIsInclusive: Bool { get }
}


Expand Down
1 change: 1 addition & 0 deletions Tests/RangeToolsTests/RangeToolsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ final class RangeToolsTests: XCTestCase {


func test_upperBoundIsInclusive() {
XCTAssertTrue (type(of: 5... ).upperBoundIsInclusive)
XCTAssertFalse(type(of: ..<7).upperBoundIsInclusive)
XCTAssertTrue (type(of: ...7).upperBoundIsInclusive)
XCTAssertFalse(type(of: 5..<7).upperBoundIsInclusive)
Expand Down

0 comments on commit 8efcac7

Please sign in to comment.