mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Revert "[stdlib] Conditional conformances for Lazy[Filter|Map]Collection"
This commit is contained in:
@@ -38,13 +38,18 @@ extension LazyCollectionProtocol where Elements == Self {
|
||||
public var elements: Self { return self }
|
||||
}
|
||||
|
||||
% for Traversal in TRAVERSALS:
|
||||
% TraversalCollection = collectionForTraversal(Traversal)
|
||||
% Self = 'Lazy' + TraversalCollection
|
||||
% Slice = TraversalCollection.replace('Collection', 'Slice')
|
||||
|
||||
/// A collection containing the same elements as a `Base` collection,
|
||||
/// but on which some operations such as `map` and `filter` are
|
||||
/// implemented lazily.
|
||||
///
|
||||
/// - See also: `LazySequenceProtocol`, `LazyCollection`
|
||||
@_fixed_layout
|
||||
public struct LazyCollection<Base : Collection> : LazyCollectionProtocol {
|
||||
public struct ${Self}<Base : ${TraversalCollection}> : LazyCollectionProtocol {
|
||||
|
||||
/// The type of the underlying collection.
|
||||
public typealias Elements = Base
|
||||
@@ -73,7 +78,7 @@ public struct LazyCollection<Base : Collection> : LazyCollectionProtocol {
|
||||
|
||||
/// Forward implementations to the base collection, to pick up any
|
||||
/// optimizations it might implement.
|
||||
extension LazyCollection : Sequence {
|
||||
extension ${Self} : Sequence {
|
||||
|
||||
public typealias Iterator = Base.Iterator
|
||||
|
||||
@@ -113,7 +118,7 @@ extension LazyCollection : Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension LazyCollection : Collection {
|
||||
extension ${Self} : ${TraversalCollection} {
|
||||
/// The position of the first element in a non-empty collection.
|
||||
///
|
||||
/// In an empty collection, `startIndex == endIndex`.
|
||||
@@ -157,7 +162,7 @@ extension LazyCollection : Collection {
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@_inlineable
|
||||
public subscript(bounds: Range<Index>) -> Slice<LazyCollection<Base>> {
|
||||
public subscript(bounds: Range<Index>) -> Slice<${Self}<Base>> {
|
||||
return Slice(base: self, bounds: bounds)
|
||||
}
|
||||
|
||||
@@ -221,10 +226,8 @@ extension LazyCollection : Collection {
|
||||
return _base.distance(from:start, to: end)
|
||||
}
|
||||
|
||||
}
|
||||
% if Traversal != 'Forward':
|
||||
|
||||
extension LazyCollection : BidirectionalCollection
|
||||
where Base : BidirectionalCollection {
|
||||
@_inlineable
|
||||
public func index(before i: Base.Index) -> Base.Index {
|
||||
return _base.index(before: i)
|
||||
@@ -234,13 +237,11 @@ extension LazyCollection : BidirectionalCollection
|
||||
public var last: Base.Element? {
|
||||
return _base.last
|
||||
}
|
||||
% end
|
||||
}
|
||||
|
||||
extension LazyCollection : RandomAccessCollection
|
||||
where Base : RandomAccessCollection {}
|
||||
|
||||
/// Augment `self` with lazy methods such as `map`, `filter`, etc.
|
||||
extension Collection {
|
||||
extension ${TraversalCollection} {
|
||||
/// A view onto this collection that provides lazy implementations of
|
||||
/// normally eager operations, such as `map` and `filter`.
|
||||
///
|
||||
@@ -248,13 +249,11 @@ extension Collection {
|
||||
/// intermediate operations from allocating storage, or when you only
|
||||
/// need a part of the final collection to avoid unnecessary computation.
|
||||
@_inlineable
|
||||
public var lazy: LazyCollection<Self> {
|
||||
return LazyCollection(_base: self)
|
||||
public var lazy: ${Self}<Self> {
|
||||
return ${Self}(_base: self)
|
||||
}
|
||||
}
|
||||
|
||||
% for Traversal in TRAVERSALS:
|
||||
% TraversalCollection = collectionForTraversal(Traversal)
|
||||
// Without this specific overload the non-re-wrapping extension on
|
||||
// LazyCollectionProtocol (below) is not selected for some reason.
|
||||
extension ${TraversalCollection} where Self : LazyCollectionProtocol {
|
||||
@@ -264,15 +263,12 @@ extension ${TraversalCollection} where Self : LazyCollectionProtocol {
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
% end
|
||||
|
||||
extension Slice: LazySequenceProtocol where Base: LazySequenceProtocol { }
|
||||
extension Slice: LazyCollectionProtocol where Base: LazyCollectionProtocol { }
|
||||
|
||||
@available(*, deprecated, renamed: "LazyCollection")
|
||||
public typealias LazyBidirectionalCollection<T> = LazyCollection<T> where T : BidirectionalCollection
|
||||
@available(*, deprecated, renamed: "LazyCollection")
|
||||
public typealias LazyRandomAccessCollection<T> = LazyCollection<T> where T : RandomAccessCollection
|
||||
// ${'Local Variables'}:
|
||||
// eval: (read-only-mode 1)
|
||||
// End:
|
||||
|
||||
Reference in New Issue
Block a user