@@ -38,18 +38,13 @@ extension LazyCollectionProtocol where Elements == Self {
38
38
public var elements : Self { return self }
39
39
}
40
40
41
- % for Traversal in TRAVERSALS:
42
- % TraversalCollection = collectionForTraversal ( Traversal)
43
- % Self = 'Lazy' + TraversalCollection
44
- % Slice = TraversalCollection . replace ( 'Collection', 'Slice')
45
-
46
41
/// A collection containing the same elements as a `Base` collection,
47
42
/// but on which some operations such as `map` and `filter` are
48
43
/// implemented lazily.
49
44
///
50
45
/// - See also: `LazySequenceProtocol`, `LazyCollection`
51
46
@_fixed_layout
52
- public struct $ { Self } < Base : $ { TraversalCollection } > : LazyCollectionProtocol {
47
+ public struct LazyCollection < Base : Collection > : LazyCollectionProtocol {
53
48
54
49
/// The type of the underlying collection.
55
50
public typealias Elements = Base
@@ -78,7 +73,7 @@ public struct ${Self}<Base : ${TraversalCollection}> : LazyCollectionProtocol {
78
73
79
74
/// Forward implementations to the base collection, to pick up any
80
75
/// optimizations it might implement.
81
- extension $ { Self } : Sequence {
76
+ extension LazyCollection : Sequence {
82
77
83
78
public typealias Iterator = Base . Iterator
84
79
@@ -118,7 +113,7 @@ extension ${Self} : Sequence {
118
113
}
119
114
}
120
115
121
- extension $ { Self } : $ { TraversalCollection } {
116
+ extension LazyCollection : Collection {
122
117
/// The position of the first element in a non-empty collection.
123
118
///
124
119
/// In an empty collection, `startIndex == endIndex`.
@@ -162,7 +157,7 @@ extension ${Self} : ${TraversalCollection} {
162
157
///
163
158
/// - Complexity: O(1)
164
159
@_inlineable
165
- public subscript( bounds: Range < Index > ) -> Slice< $ { Self } < Base>> {
160
+ public subscript( bounds: Range < Index > ) -> Slice < LazyCollection < Base > > {
166
161
return Slice ( base: self , bounds: bounds)
167
162
}
168
163
@@ -226,8 +221,10 @@ extension ${Self} : ${TraversalCollection} {
226
221
return _base. distance ( from: start, to: end)
227
222
}
228
223
229
- % if Traversal != 'Forward' :
224
+ }
230
225
226
+ extension LazyCollection : BidirectionalCollection
227
+ where Base : BidirectionalCollection {
231
228
@_inlineable
232
229
public func index( before i: Base . Index ) -> Base . Index {
233
230
return _base. index ( before: i)
@@ -237,23 +234,27 @@ extension ${Self} : ${TraversalCollection} {
237
234
public var last : Base . Element ? {
238
235
return _base. last
239
236
}
240
- % end
241
237
}
242
238
239
+ extension LazyCollection : RandomAccessCollection
240
+ where Base : RandomAccessCollection { }
241
+
243
242
/// Augment `self` with lazy methods such as `map`, `filter`, etc.
244
- extension $ { TraversalCollection } {
243
+ extension Collection {
245
244
/// A view onto this collection that provides lazy implementations of
246
245
/// normally eager operations, such as `map` and `filter`.
247
246
///
248
247
/// Use the `lazy` property when chaining operations to prevent
249
248
/// intermediate operations from allocating storage, or when you only
250
249
/// need a part of the final collection to avoid unnecessary computation.
251
250
@_inlineable
252
- public var lazy: $ { Self } < Self> {
253
- return $ { Self } ( _base: self )
251
+ public var lazy : LazyCollection < Self > {
252
+ return LazyCollection ( _base: self )
254
253
}
255
254
}
256
255
256
+ % for Traversal in TRAVERSALS:
257
+ % TraversalCollection = collectionForTraversal ( Traversal)
257
258
// Without this specific overload the non-re-wrapping extension on
258
259
// LazyCollectionProtocol (below) is not selected for some reason.
259
260
extension ${ TraversalCollection} where Self : LazyCollectionProtocol {
@@ -263,12 +264,15 @@ extension ${TraversalCollection} where Self : LazyCollectionProtocol {
263
264
return self
264
265
}
265
266
}
266
-
267
267
% end
268
268
269
269
extension Slice : LazySequenceProtocol where Base: LazySequenceProtocol { }
270
270
extension Slice : LazyCollectionProtocol where Base: LazyCollectionProtocol { }
271
271
272
+ @available ( * , deprecated, renamed: " LazyCollection " )
273
+ public typealias LazyBidirectionalCollection < T> = LazyCollection < T > where T : BidirectionalCollection
274
+ @available ( * , deprecated, renamed: " LazyCollection " )
275
+ public typealias LazyRandomAccessCollection < T> = LazyCollection < T > where T : RandomAccessCollection
272
276
// ${'Local Variables'}:
273
277
// eval: (read-only-mode 1)
274
278
// End:
0 commit comments