@@ -97,65 +97,8 @@ public struct LazyFilterSequence<Base : Sequence>
97
97
}
98
98
99
99
/// The `Index` used for subscripting a `LazyFilterCollection`.
100
- ///
101
- /// The positions of a `LazyFilterIndex` correspond to those positions
102
- /// `p` in its underlying collection `c` such that `c[p]`
103
- /// satisfies the predicate with which the `LazyFilterIndex` was
104
- /// initialized.
105
- ///
106
- /// - Note: The performance of advancing a `LazyFilterIndex`
107
- /// depends on how sparsely the filtering predicate is satisfied,
108
- /// and may not offer the usual performance given by models of
109
- /// `Collection`.
110
- public struct LazyFilterIndex < Base : Collection > {
111
-
112
- /// The position corresponding to `self` in the underlying collection.
113
- public let base : Base . Index
114
- }
115
-
116
- extension LazyFilterIndex : Comparable {
117
- public static func == (
118
- lhs: LazyFilterIndex < Base > ,
119
- rhs: LazyFilterIndex < Base >
120
- ) -> Bool {
121
- return lhs. base == rhs. base
122
- }
123
-
124
- public static func != (
125
- lhs: LazyFilterIndex < Base > ,
126
- rhs: LazyFilterIndex < Base >
127
- ) -> Bool {
128
- return lhs. base != rhs. base
129
- }
130
-
131
- public static func < (
132
- lhs: LazyFilterIndex < Base > ,
133
- rhs: LazyFilterIndex < Base >
134
- ) -> Bool {
135
- return lhs. base < rhs. base
136
- }
137
-
138
- public static func <= (
139
- lhs: LazyFilterIndex < Base > ,
140
- rhs: LazyFilterIndex < Base >
141
- ) -> Bool {
142
- return lhs. base <= rhs. base
143
- }
144
-
145
- public static func >= (
146
- lhs: LazyFilterIndex < Base > ,
147
- rhs: LazyFilterIndex < Base >
148
- ) -> Bool {
149
- return lhs. base >= rhs. base
150
- }
151
-
152
- public static func > (
153
- lhs: LazyFilterIndex < Base > ,
154
- rhs: LazyFilterIndex < Base >
155
- ) -> Bool {
156
- return lhs. base > rhs. base
157
- }
158
- }
100
+ @available ( swift, deprecated: 3.1 , obsoleted: 4.0 , message: " Use Base.Index " )
101
+ public typealias LazyFilterIndex < Base : Collection > = Base . Index
159
102
160
103
// FIXME(ABI)#27 (Conditional Conformance): `LazyFilter*Collection` types should be
161
104
// collapsed into one `LazyFilterCollection` using conditional conformances.
@@ -170,20 +113,23 @@ extension LazyFilterIndex : Comparable {
170
113
/// underlying collection that satisfy a predicate.
171
114
///
172
115
/// - Note: The performance of accessing `startIndex`, `first`, any methods
173
- /// that depend on `startIndex`, or of advancing a `LazyFilterIndex` depends
116
+ /// that depend on `startIndex`, or of advancing an index depends
174
117
/// on how sparsely the filtering predicate is satisfied, and may not offer
175
118
/// the usual performance given by `Collection`. Be aware, therefore, that
176
119
/// general operations on `LazyFilterCollection` instances may not have the
177
120
/// documented complexity.
178
121
public struct ${ Self} <
179
122
Base : ${ collectionForTraversal ( Traversal) }
180
- > : LazyCollectionProtocol, ${ collectionForTraversal ( Traversal) } {
123
+ > : LazyCollectionProtocol, ${ collectionForTraversal ( Traversal) }
124
+ // FIXME(ABI): Recursive protocol conformances
125
+ where Base. SubSequence : ${ collectionForTraversal ( Traversal) }
126
+ {
181
127
182
128
/// A type that represents a valid position in the collection.
183
129
///
184
130
/// Valid indices consist of the position of every element and a
185
131
/// "past the end" position that's not valid for use as a subscript.
186
- public typealias Index = LazyFilterIndex < Base>
132
+ public typealias Index = Base . Index
187
133
188
134
public typealias IndexDistance = Base . IndexDistance
189
135
@@ -209,7 +155,7 @@ public struct ${Self}<
209
155
while index != _base. endIndex && !_predicate( _base [ index] ) {
210
156
_base. formIndex ( after: & index)
211
157
}
212
- return LazyFilterIndex ( base : index)
158
+ return index
213
159
}
214
160
215
161
/// The collection's "past the end" position---that is, the position one
@@ -218,7 +164,7 @@ public struct ${Self}<
218
164
/// `endIndex` is always reachable from `startIndex` by zero or more
219
165
/// applications of `index(after:)`.
220
166
public var endIndex : Index {
221
- return LazyFilterIndex ( base : _base. endIndex)
167
+ return _base. endIndex
222
168
}
223
169
224
170
// TODO: swift-3-indexing-model - add docs
@@ -230,12 +176,12 @@ public struct ${Self}<
230
176
231
177
public func formIndex( after i: inout Index ) {
232
178
// TODO: swift-3-indexing-model: _failEarlyRangeCheck i?
233
- var index = i. base
179
+ var index = i
234
180
_precondition ( index != _base. endIndex, " can't advance past endIndex " )
235
181
repeat {
236
182
_base. formIndex ( after: & index)
237
183
} while index != _base. endIndex && !_predicate( _base [ index] )
238
- i = LazyFilterIndex ( base : index)
184
+ i = index
239
185
}
240
186
241
187
% if Traversal == 'Bidirectional':
@@ -247,12 +193,12 @@ public struct ${Self}<
247
193
248
194
public func formIndex( before i: inout Index ) {
249
195
// TODO: swift-3-indexing-model: _failEarlyRangeCheck i?
250
- var index = i. base
196
+ var index = i
251
197
_precondition ( index != _base. startIndex, " can't retreat before startIndex " )
252
198
repeat {
253
199
_base. formIndex ( before: & index)
254
200
} while !_predicate( _base [ index] )
255
- i = LazyFilterIndex ( base : index)
201
+ i = index
256
202
}
257
203
% end
258
204
@@ -261,22 +207,14 @@ public struct ${Self}<
261
207
/// - Precondition: `position` is a valid position in `self` and
262
208
/// `position != endIndex`.
263
209
public subscript( position: Index) - > Base. Iterator. Element {
264
- return _base [ position. base ]
210
+ return _base [ position]
265
211
}
266
212
267
- public subscript( bounds: Range < Index > ) -> ${ Slice } < $ { Self} < Base> > {
268
- return ${ Slice } ( base : self , bounds : bounds )
213
+ public subscript( bounds: Range < Index > ) -> ${ Self} < Base . SubSequence > {
214
+ return ${ Self } < Base . SubSequence > ( _base : _base [ bounds ] , _predicate )
269
215
}
270
216
271
- // FIXME(ABI)#28 (Associated Types with where clauses): we actually want to add:
272
- //
273
- // typealias SubSequence = ${Self}<Base.SubSequence>
274
- //
275
- // so that all slicing optimizations of the base collection can kick in.
276
- //
277
- // We can't do that right now though, because that would force a lot of
278
- // constraints on `Base.SubSequence`, limiting the possible contexts where
279
- // the `.lazy.filter` API can be used.
217
+ public typealias SubSequence = ${ Self} < Base . SubSequence>
280
218
281
219
/// Returns an iterator over the elements of this sequence.
282
220
///
@@ -310,11 +248,12 @@ extension LazySequenceProtocol {
310
248
% for Traversal in [ 'Forward', 'Bidirectional'] :
311
249
312
250
extension LazyCollectionProtocol
313
- % if Traversal != 'Forward':
314
251
where
252
+ % if Traversal != 'Forward':
315
253
Self : ${ collectionForTraversal ( Traversal) } ,
316
- Elements : ${ collectionForTraversal ( Traversal) }
254
+ Elements : ${ collectionForTraversal ( Traversal) } ,
317
255
% end
256
+ Self . Elements. SubSequence : ${ collectionForTraversal ( Traversal) }
318
257
{
319
258
/// Returns the elements of `self` that satisfy `predicate`.
320
259
///
0 commit comments