|
18 | 18 | /// x.split(separator:maxSplits:omittingEmptySubsequences)
|
19 | 19 | ///
|
20 | 20 | /// where `x` conforms to `LazyCollectionProtocol`.
|
21 |
| -public struct LazySplitCollection<Base: LazyCollectionProtocol> |
22 |
| -where Base.Elements.Index == Base.Index { |
| 21 | +public struct LazySplitCollection<Base: Collection> { |
23 | 22 | internal let base: Base
|
24 | 23 | internal let isSeparator: (Base.Element) -> Bool
|
25 | 24 | internal let maxSplits: Int
|
@@ -54,7 +53,7 @@ extension LazySplitCollection {
|
54 | 53 | }
|
55 | 54 |
|
56 | 55 | extension LazySplitCollection.Iterator: IteratorProtocol {
|
57 |
| - public typealias Element = Base.Elements.SubSequence |
| 56 | + public typealias Element = Base.SubSequence |
58 | 57 |
|
59 | 58 | public mutating func next() -> Element? {
|
60 | 59 | /// Separators mark the points where we want to split (cut in two) the base collection, removing
|
@@ -100,7 +99,7 @@ extension LazySplitCollection.Iterator: IteratorProtocol {
|
100 | 99 | /// number of separators we've encountered). This happens when the last element of the base
|
101 | 100 | /// collection is a separator. Return one last empty subsequence.
|
102 | 101 | sequenceLength += 1
|
103 |
| - return base.elements[subsequenceStart..<subsequenceStart] |
| 102 | + return base[subsequenceStart..<subsequenceStart] |
104 | 103 | } else {
|
105 | 104 | return nil
|
106 | 105 | }
|
@@ -133,7 +132,7 @@ extension LazySplitCollection.Iterator: IteratorProtocol {
|
133 | 132 | subsequenceStart = subsequenceEnd < base.endIndex ? base.index(after: subsequenceEnd) : base.endIndex
|
134 | 133 | }
|
135 | 134 |
|
136 |
| - return base.elements[subsequenceStart..<subsequenceEnd] |
| 135 | + return base[subsequenceStart..<subsequenceEnd] |
137 | 136 | }
|
138 | 137 | }
|
139 | 138 |
|
@@ -228,11 +227,11 @@ extension LazyCollectionProtocol where Elements.Index == Index {
|
228 | 227 | maxSplits: Int = Int.max,
|
229 | 228 | omittingEmptySubsequences: Bool = true,
|
230 | 229 | whereSeparator isSeparator: @escaping (Element) -> Bool
|
231 |
| - ) -> LazySplitCollection<Self> { |
| 230 | + ) -> LazySplitCollection<Elements> { |
232 | 231 | precondition(maxSplits >= 0, "Must take zero or more splits")
|
233 | 232 |
|
234 | 233 | return LazySplitCollection(
|
235 |
| - base: self, |
| 234 | + base: elements, |
236 | 235 | isSeparator: isSeparator,
|
237 | 236 | maxSplits: maxSplits,
|
238 | 237 | omittingEmptySubsequences: omittingEmptySubsequences
|
@@ -318,11 +317,11 @@ extension LazyCollectionProtocol where Element: Equatable, Elements.Index == Ind
|
318 | 317 | separator: Element,
|
319 | 318 | maxSplits: Int = Int.max,
|
320 | 319 | omittingEmptySubsequences: Bool = true
|
321 |
| - ) -> LazySplitCollection<Self> { |
| 320 | + ) -> LazySplitCollection<Elements> { |
322 | 321 | precondition(maxSplits >= 0, "Must take zero or more splits")
|
323 | 322 |
|
324 | 323 | return LazySplitCollection(
|
325 |
| - base: self, |
| 324 | + base: elements, |
326 | 325 | isSeparator: { $0 == separator },
|
327 | 326 | maxSplits: maxSplits,
|
328 | 327 | omittingEmptySubsequences: omittingEmptySubsequences
|
|
0 commit comments