Added Strideable stubs to Failable<Strideable, T> type

This commit is contained in:
Caleb Kleveter 2018-11-28 16:21:27 -06:00
parent 3573962d26
commit 7c4d7d0984
No known key found for this signature in database
GPG Key ID: B38DBD5CF2C98D69
1 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,56 @@
extension Failable where T: Strideable {
/// See [`Strideable.Stride`](https://developer.apple.com/documentation/swift/strideable/1541220-stride).
public typealias Stride = T.Stride
/// See [`Strideable.advance(by:)`](https://developer.apple.com/documentation/swift/strideable/1641148-advanced).
public func advance(by n: Stride)throws -> Failable<T, Validations> {
return try Failable(self.value.advanced(by: n))
}
/// See [`Strideable.distance(to:)`](https://developer.apple.com/documentation/swift/strideable/1641148-advanced).
public func distance(to other: Failable<T, Validations>) -> Stride {
return self.value.distance(to: other.value)
}
/// See [`Strideable.+(_:_:)`](https://developer.apple.com/documentation/swift/strideable/2885404).
public static func + (lhs: Failable<T, Validations>, rhs: Stride)throws -> Failable<T, Validations> {
return try lhs.advance(by: rhs)
}
/// See [`Strideable.+(_:_:)`](https://developer.apple.com/documentation/swift/strideable/2886679).
public static func + (lhs: Stride, rhs: Failable<T, Validations>)throws -> Failable<T, Validations> {
return try rhs.advance(by: lhs)
}
/// See [`Strideable.+=(_:_:)`](https://developer.apple.com/documentation/swift/strideable/2884440).
public static func += (lhs: inout Failable<T, Validations>, rhs: Stride)throws {
try lhs <~ lhs.advance(by: rhs).value
}
/// See [`Strideable.-(_:_:)`](https://developer.apple.com/documentation/swift/strideable/2884623).
public static func - (lhs: Failable<T, Validations>, rhs: Stride)throws -> Failable<T, Validations> {
return try lhs.advance(by: -rhs)
}
/// See [`Strideable.-(_:_:)`](https://developer.apple.com/documentation/swift/strideable/2886160).
public static func - (lhs: Failable<T, Validations>, rhs: Failable<T, Validations>) -> Stride {
return rhs.distance(to: lhs)
}
/// See [`Strideable.-=(_:_:)`](https://developer.apple.com/documentation/swift/strideable/2885177).
public static func -= (lhs: inout Failable<T, Validations>, rhs: Stride)throws {
try lhs <~ lhs.advance(by: -rhs).value
}
}
extension Failable where T: Strideable, T.Stride: SignedInteger {
/// See [`Stridable....(_:_:)`](https://developer.apple.com/documentation/swift/strideable/2950083).
public static func ... (
lhs: Failable<T, Validations>,
rhs: Failable<T, Validations>
)throws -> Failable<ClosedRange<T>, ElementValidation<ClosedRange<T>, Validations>> {
return try (lhs.value...rhs.value).failable()
}
}