Conformed Failable<Collection, T> type to Collection protocol

This commit is contained in:
Caleb Kleveter 2018-11-30 08:27:55 -06:00
parent 12938b2c5d
commit 226ad01b84
No known key found for this signature in database
GPG Key ID: B38DBD5CF2C98D69
2 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,29 @@
extension Failable: Collection where T: Collection {
/// See [`Collection.SubSequence`](https://developer.apple.com/documentation/swift/collection/1641276-subsequence)
public typealias SubSequence = T.SubSequence
/// See [`Collection.Index`](https://developer.apple.com/documentation/swift/collection/2943866-index).
public typealias Index = T.Index
/// See [`Collection.startIndex`](https://developer.apple.com/documentation/swift/collection/2946080-startindex).
public var startIndex: T.Index {
return self.value.startIndex
}
/// See [`Collection.endIndex`](https://developer.apple.com/documentation/swift/collection/2944204-endindex).
public var endIndex: T.Index {
return self.value.endIndex
}
/// See [`Collection.[]`](https://developer.apple.com/documentation/swift/collection/1641358-subscript).
public subscript(position: Index) -> Element {
return self.value[position]
}
/// See [`Collection.index(after:)`](https://developer.apple.com/documentation/swift/collection/2943746-index).
public func index(after i: T.Index) -> T.Index {
return self.value.index(after: i)
}
}

View File

@ -10,4 +10,41 @@ extension Failable: Sequence where T: Sequence {
public func makeIterator() -> T.Iterator {
return self.value.makeIterator()
}
/// See [`Sequence.split(separator:maxSplits:omittingEmptySubsequences:)`](https://developer.apple.com/documentation/swift/sequence/2908109-split).
public func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator isSeparator: (T.Element) throws -> Bool) rethrows
-> [T.SubSequence]
{
return try self.value.split(maxSplits: maxSplits, omittingEmptySubsequences: omittingEmptySubsequences, whereSeparator: isSeparator)
}
/// See [`Sequence.suffix(_:)`](https://developer.apple.com/documentation/swift/sequence/2965540-suffix).
public func suffix(_ maxLength: Int) -> T.SubSequence {
return self.value.suffix(maxLength)
}
/// See [`Sequence.prefix(while:)`](https://developer.apple.com/documentation/swift/sequence/2965528-prefix)
public func prefix(while predicate: (T.Element) throws -> Bool) rethrows -> T.SubSequence {
return try self.value.prefix(while: predicate)
}
/// See [`Sequence.prefix(_:)`](https://developer.apple.com/documentation/swift/sequence/2965524-prefix).
public func prefix(_ maxLength: Int) -> T.SubSequence {
return self.value.prefix(maxLength)
}
/// See [`Sequence.drop(while:)`](https://developer.apple.com/documentation/swift/sequence/2965501-drop).
public func drop(while predicate: (T.Element) throws -> Bool) rethrows -> T.SubSequence {
return try self.value.drop(while: predicate)
}
/// See [`Sequence.dropLast`](https://developer.apple.com/documentation/swift/sequence/2965508-droplast).
public func dropLast(_ k: Int) -> T.SubSequence {
return self.value.dropLast(k)
}
/// See [`Sequence.dropFirst(_:)`](https://developer.apple.com/documentation/swift/sequence/2965504-dropfirst).
public func dropFirst(_ k: Int) -> T.SubSequence {
return self.value.dropFirst(k)
}
}