mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-28 04:44:20 +00:00
Rename types to include a Sequence or Collection suffix, and clean up some guides
This commit is contained in:
1 parent
9f628005fe
commit
88be07a691
32 files changed
+499
-429
No files matched your search
@@ -10,7 +10,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A concatenation of two sequences with the same element type.
|
||||
public struct Chain2<Base1: Sequence, Base2: Sequence>
|
||||
public struct Chain2Sequence<Base1: Sequence, Base2: Sequence>
|
||||
where Base1.Element == Base2.Element
|
||||
{
|
||||
/// The first sequence in this chain.
|
||||
@@ -28,7 +28,7 @@ public struct Chain2<Base1: Sequence, Base2: Sequence>
|
||||
}
|
||||
}
|
||||
|
||||
extension Chain2: Sequence {
|
||||
extension Chain2Sequence: Sequence {
|
||||
/// The iterator for a `Chain2` sequence.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
@@ -38,7 +38,7 @@ extension Chain2: Sequence {
|
||||
internal var iterator2: Base2.Iterator
|
||||
|
||||
@inlinable
|
||||
internal init(_ concatenation: Chain2) {
|
||||
internal init(_ concatenation: Chain2Sequence) {
|
||||
iterator1 = concatenation.base1.makeIterator()
|
||||
iterator2 = concatenation.base2.makeIterator()
|
||||
}
|
||||
@@ -55,7 +55,7 @@ extension Chain2: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension Chain2: Collection where Base1: Collection, Base2: Collection {
|
||||
extension Chain2Sequence: Collection where Base1: Collection, Base2: Collection {
|
||||
/// A position in a `Chain2` collection.
|
||||
public struct Index: Comparable {
|
||||
// The internal index representation, which can either be an index of the
|
||||
@@ -263,7 +263,7 @@ extension Chain2: Collection where Base1: Collection, Base2: Collection {
|
||||
}
|
||||
}
|
||||
|
||||
extension Chain2: BidirectionalCollection
|
||||
extension Chain2Sequence: BidirectionalCollection
|
||||
where Base1: BidirectionalCollection, Base2: BidirectionalCollection
|
||||
{
|
||||
@inlinable
|
||||
@@ -280,7 +280,7 @@ extension Chain2: BidirectionalCollection
|
||||
}
|
||||
}
|
||||
|
||||
extension Chain2: RandomAccessCollection
|
||||
extension Chain2Sequence: RandomAccessCollection
|
||||
where Base1: RandomAccessCollection, Base2: RandomAccessCollection {}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -314,20 +314,23 @@ extension Chain2: RandomAccessCollection
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@inlinable
|
||||
public func chain<S1, S2>(_ s1: S1, _ s2: S2) -> Chain2<S1, S2> {
|
||||
Chain2(base1: s1, base2: s2)
|
||||
public func chain<S1, S2>(_ s1: S1, _ s2: S2) -> Chain2Sequence<S1, S2> {
|
||||
Chain2Sequence(base1: s1, base2: s2)
|
||||
}
|
||||
|
||||
// MARK: - Deprecations
|
||||
|
||||
@available(*, deprecated, renamed: "Chain2")
|
||||
public typealias Chain = Chain2
|
||||
@available(*, deprecated, renamed: "Chain2Sequence")
|
||||
public typealias Chain = Chain2Sequence
|
||||
|
||||
@available(*, deprecated, renamed: "Chain2Sequence")
|
||||
public typealias Chain2 = Chain2Sequence
|
||||
|
||||
extension Sequence {
|
||||
@available(*, deprecated, message: "Use the chain(_:_:) function, instead.")
|
||||
public func chained<S: Sequence>(with other: S) -> Chain2<Self, S>
|
||||
public func chained<S: Sequence>(with other: S) -> Chain2Sequence<Self, S>
|
||||
where Element == S.Element
|
||||
{
|
||||
Chain2(base1: self, base2: other)
|
||||
Chain2Sequence(base1: self, base2: other)
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
/// predicate.
|
||||
///
|
||||
/// Call `lazy.chunked(by:)` on a collection to create an instance of this type.
|
||||
public struct ChunkedBy<Base: Collection, Subject> {
|
||||
public struct ChunkedByCollection<Base: Collection, Subject> {
|
||||
/// The collection that this instance provides a view onto.
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
@@ -47,7 +47,7 @@ public struct ChunkedBy<Base: Collection, Subject> {
|
||||
}
|
||||
}
|
||||
|
||||
extension ChunkedBy: LazyCollectionProtocol {
|
||||
extension ChunkedByCollection: LazyCollectionProtocol {
|
||||
/// A position in a chunked collection.
|
||||
public struct Index: Comparable {
|
||||
/// The range corresponding to the chunk at this position.
|
||||
@@ -112,9 +112,9 @@ extension ChunkedBy: LazyCollectionProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
extension ChunkedBy.Index: Hashable where Base.Index: Hashable {}
|
||||
extension ChunkedByCollection.Index: Hashable where Base.Index: Hashable {}
|
||||
|
||||
extension ChunkedBy: BidirectionalCollection
|
||||
extension ChunkedByCollection: BidirectionalCollection
|
||||
where Base: BidirectionalCollection
|
||||
{
|
||||
/// Returns the index in the base collection of the start of the chunk ending
|
||||
@@ -139,19 +139,22 @@ extension ChunkedBy: BidirectionalCollection
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "ChunkedBy")
|
||||
public typealias LazyChunked<Base: Collection, Subject> = ChunkedBy<Base, Subject>
|
||||
@available(*, deprecated, renamed: "ChunkedByCollection")
|
||||
public typealias LazyChunked<Base: Collection, Subject> = ChunkedByCollection<Base, Subject>
|
||||
|
||||
@available(*, deprecated, renamed: "ChunkedBy")
|
||||
public typealias Chunked<Base: Collection, Subject> = ChunkedBy<Base, Subject>
|
||||
@available(*, deprecated, renamed: "ChunkedByCollection")
|
||||
public typealias Chunked<Base: Collection, Subject> = ChunkedByCollection<Base, Subject>
|
||||
|
||||
@available(*, deprecated, renamed: "ChunkedByCollection")
|
||||
public typealias ChunkedBy<Base: Collection, Subject> = ChunkedByCollection<Base, Subject>
|
||||
|
||||
/// A collection wrapper that breaks a collection into chunks based on a
|
||||
/// predicate.
|
||||
///
|
||||
/// Call `lazy.chunked(on:)` on a collection to create an instance of this type.
|
||||
public struct ChunkedOn<Base: Collection, Subject> {
|
||||
public struct ChunkedOnCollection<Base: Collection, Subject> {
|
||||
@usableFromInline
|
||||
internal var chunked: ChunkedBy<Base, Subject>
|
||||
internal var chunked: ChunkedByCollection<Base, Subject>
|
||||
|
||||
@inlinable
|
||||
internal init(
|
||||
@@ -159,12 +162,12 @@ public struct ChunkedOn<Base: Collection, Subject> {
|
||||
projection: @escaping (Base.Element) -> Subject,
|
||||
belongInSameGroup: @escaping (Subject, Subject) -> Bool
|
||||
) {
|
||||
self.chunked = ChunkedBy(base: base, projection: projection, belongInSameGroup: belongInSameGroup)
|
||||
self.chunked = ChunkedByCollection(base: base, projection: projection, belongInSameGroup: belongInSameGroup)
|
||||
}
|
||||
}
|
||||
|
||||
extension ChunkedOn: LazyCollectionProtocol {
|
||||
public typealias Index = ChunkedBy<Base, Subject>.Index
|
||||
extension ChunkedOnCollection: LazyCollectionProtocol {
|
||||
public typealias Index = ChunkedByCollection<Base, Subject>.Index
|
||||
|
||||
@inlinable
|
||||
public var startIndex: Index {
|
||||
@@ -189,7 +192,7 @@ extension ChunkedOn: LazyCollectionProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
extension ChunkedOn: BidirectionalCollection where Base: BidirectionalCollection {
|
||||
extension ChunkedOnCollection: BidirectionalCollection where Base: BidirectionalCollection {
|
||||
public func index(before i: Index) -> Index {
|
||||
chunked.index(before: i)
|
||||
}
|
||||
@@ -207,8 +210,8 @@ extension LazyCollectionProtocol {
|
||||
@inlinable
|
||||
public func chunked(
|
||||
by belongInSameGroup: @escaping (Element, Element) -> Bool
|
||||
) -> ChunkedBy<Elements, Element> {
|
||||
ChunkedBy(
|
||||
) -> ChunkedByCollection<Elements, Element> {
|
||||
ChunkedByCollection(
|
||||
base: elements,
|
||||
projection: { $0 },
|
||||
belongInSameGroup: belongInSameGroup)
|
||||
@@ -221,8 +224,8 @@ extension LazyCollectionProtocol {
|
||||
@inlinable
|
||||
public func chunked<Subject: Equatable>(
|
||||
on projection: @escaping (Element) -> Subject
|
||||
) -> ChunkedOn<Elements, Subject> {
|
||||
ChunkedOn(
|
||||
) -> ChunkedOnCollection<Elements, Subject> {
|
||||
ChunkedOnCollection(
|
||||
base: elements,
|
||||
projection: projection,
|
||||
belongInSameGroup: ==)
|
||||
@@ -307,7 +310,7 @@ extension Collection {
|
||||
/// * `c.chunks(ofCount: 3)` does not create new storage
|
||||
/// * `c.chunks(ofCount: 3).map(f)` maps eagerly and returns a new array
|
||||
/// * `c.lazy.chunks(ofCount: 3).map(f)` maps lazily and returns a `LazyMapCollection`
|
||||
public struct ChunkedByCount<Base: Collection> {
|
||||
public struct ChunksOfCountCollection<Base: Collection> {
|
||||
|
||||
public typealias Element = Base.SubSequence
|
||||
|
||||
@@ -338,7 +341,7 @@ public struct ChunkedByCount<Base: Collection> {
|
||||
}
|
||||
}
|
||||
|
||||
extension ChunkedByCount: Collection {
|
||||
extension ChunksOfCountCollection: Collection {
|
||||
public struct Index {
|
||||
@usableFromInline
|
||||
internal let baseRange: Range<Base.Index>
|
||||
@@ -377,21 +380,21 @@ extension ChunkedByCount: Collection {
|
||||
}
|
||||
}
|
||||
|
||||
extension ChunkedByCount.Index: Comparable {
|
||||
extension ChunksOfCountCollection.Index: Comparable {
|
||||
@inlinable
|
||||
public static func == (lhs: ChunkedByCount.Index,
|
||||
rhs: ChunkedByCount.Index) -> Bool {
|
||||
public static func == (lhs: ChunksOfCountCollection.Index,
|
||||
rhs: ChunksOfCountCollection.Index) -> Bool {
|
||||
lhs.baseRange.lowerBound == rhs.baseRange.lowerBound
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public static func < (lhs: ChunkedByCount.Index,
|
||||
rhs: ChunkedByCount.Index) -> Bool {
|
||||
public static func < (lhs: ChunksOfCountCollection.Index,
|
||||
rhs: ChunksOfCountCollection.Index) -> Bool {
|
||||
lhs.baseRange.lowerBound < rhs.baseRange.lowerBound
|
||||
}
|
||||
}
|
||||
|
||||
extension ChunkedByCount:
|
||||
extension ChunksOfCountCollection:
|
||||
BidirectionalCollection, RandomAccessCollection
|
||||
where Base: RandomAccessCollection {
|
||||
@inlinable
|
||||
@@ -414,7 +417,7 @@ where Base: RandomAccessCollection {
|
||||
}
|
||||
}
|
||||
|
||||
extension ChunkedByCount {
|
||||
extension ChunksOfCountCollection {
|
||||
@inlinable
|
||||
public func distance(from start: Index, to end: Index) -> Int {
|
||||
let distance =
|
||||
@@ -572,16 +575,16 @@ extension Collection {
|
||||
///
|
||||
/// - Complexity: O(*n*), because the start index is pre-computed.
|
||||
@inlinable
|
||||
public func chunks(ofCount count: Int) -> ChunkedByCount<Self> {
|
||||
public func chunks(ofCount count: Int) -> ChunksOfCountCollection<Self> {
|
||||
precondition(count > 0, "Cannot chunk with count <= 0!")
|
||||
return ChunkedByCount(_base: self, _chunkCount: count)
|
||||
return ChunksOfCountCollection(_base: self, _chunkCount: count)
|
||||
}
|
||||
}
|
||||
|
||||
extension ChunkedByCount.Index: Hashable where Base.Index: Hashable {}
|
||||
extension ChunksOfCountCollection.Index: Hashable where Base.Index: Hashable {}
|
||||
|
||||
// Lazy conditional conformance.
|
||||
extension ChunkedByCount: LazySequenceProtocol
|
||||
extension ChunksOfCountCollection: LazySequenceProtocol
|
||||
where Base: LazySequenceProtocol {}
|
||||
extension ChunkedByCount: LazyCollectionProtocol
|
||||
extension ChunksOfCountCollection: LazyCollectionProtocol
|
||||
where Base: LazyCollectionProtocol {}
|
||||
@@ -10,7 +10,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A collection wrapper that generates combinations of a base collection.
|
||||
public struct Combinations<Base: Collection> {
|
||||
public struct CombinationsSequence<Base: Collection> {
|
||||
/// The collection to iterate over for combinations.
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
@@ -76,7 +76,7 @@ public struct Combinations<Base: Collection> {
|
||||
}
|
||||
}
|
||||
|
||||
extension Combinations: Sequence {
|
||||
extension CombinationsSequence: Sequence {
|
||||
/// The iterator for a `Combinations` instance.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
@@ -99,7 +99,7 @@ extension Combinations: Sequence {
|
||||
internal var indexes: [Base.Index]
|
||||
|
||||
@inlinable
|
||||
internal init(_ combinations: Combinations) {
|
||||
internal init(_ combinations: CombinationsSequence) {
|
||||
self.base = combinations.base
|
||||
self.kRange = combinations.kRange ?? 0..<0
|
||||
self.indexes = Array(combinations.base.indices.prefix(kRange.lowerBound))
|
||||
@@ -180,7 +180,7 @@ extension Combinations: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension Combinations: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
extension CombinationsSequence: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// combinations(ofCount:)
|
||||
@@ -251,8 +251,8 @@ extension Collection {
|
||||
@inlinable
|
||||
public func combinations<R: RangeExpression>(
|
||||
ofCount kRange: R
|
||||
) -> Combinations<Self> where R.Bound == Int {
|
||||
return Combinations(self, kRange: kRange)
|
||||
) -> CombinationsSequence<Self> where R.Bound == Int {
|
||||
return CombinationsSequence(self, kRange: kRange)
|
||||
}
|
||||
|
||||
/// Returns a collection of combinations of this collection's elements, with
|
||||
@@ -285,8 +285,8 @@ extension Collection {
|
||||
/// is the number of elements in the base collection, since `Combinations`
|
||||
/// accesses the `count` of the base collection.
|
||||
@inlinable
|
||||
public func combinations(ofCount k: Int) -> Combinations<Self> {
|
||||
public func combinations(ofCount k: Int) -> CombinationsSequence<Self> {
|
||||
precondition(k >= 0, "Can't have combinations with a negative number of elements.")
|
||||
return Combinations(self, k: k)
|
||||
return CombinationsSequence(self, k: k)
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A collection wrapper that repeats the elements of a base collection.
|
||||
public struct Cycle<Base: Collection> {
|
||||
public struct CycledSequence<Base: Collection> {
|
||||
/// The collection to repeat.
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
@@ -21,7 +21,7 @@ public struct Cycle<Base: Collection> {
|
||||
}
|
||||
}
|
||||
|
||||
extension Cycle: Sequence {
|
||||
extension CycledSequence: Sequence {
|
||||
/// The iterator for a `Cycle` sequence.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
@@ -55,36 +55,33 @@ extension Cycle: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension Cycle: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
extension CycledSequence: LazySequenceProtocol
|
||||
where Base: LazySequenceProtocol {}
|
||||
|
||||
|
||||
/// A collection wrapper that repeats the elements of a base collection for a
|
||||
/// finite number of times.
|
||||
public struct FiniteCycle<Base: Collection> {
|
||||
/// A Product2 instance for iterating the Base collection.
|
||||
public struct CycledTimesCollection<Base: Collection> {
|
||||
/// A `Product2Sequence` instance for iterating the base collection.
|
||||
@usableFromInline
|
||||
internal let product: Product2<Range<Int>, Base>
|
||||
internal let product: Product2Sequence<Range<Int>, Base>
|
||||
|
||||
@inlinable
|
||||
internal init(base: Base, times: Int) {
|
||||
self.product = Product2(0..<times, base)
|
||||
self.product = Product2Sequence(0..<times, base)
|
||||
}
|
||||
}
|
||||
|
||||
extension FiniteCycle: LazySequenceProtocol, LazyCollectionProtocol
|
||||
where Base: LazyCollectionProtocol { }
|
||||
|
||||
extension FiniteCycle: Collection {
|
||||
|
||||
extension CycledTimesCollection: Collection {
|
||||
public typealias Element = Base.Element
|
||||
|
||||
public struct Index: Comparable {
|
||||
/// The index corresponding to the Product2 index at this position.
|
||||
@usableFromInline
|
||||
internal let productIndex: Product2<Range<Int>, Base>.Index
|
||||
internal let productIndex: Product2Sequence<Range<Int>, Base>.Index
|
||||
|
||||
@inlinable
|
||||
internal init(_ productIndex: Product2<Range<Int>, Base>.Index) {
|
||||
internal init(_ productIndex: Product2Sequence<Range<Int>, Base>.Index) {
|
||||
self.productIndex = productIndex
|
||||
}
|
||||
|
||||
@@ -151,7 +148,7 @@ extension FiniteCycle: Collection {
|
||||
}
|
||||
}
|
||||
|
||||
extension FiniteCycle: BidirectionalCollection
|
||||
extension CycledTimesCollection: BidirectionalCollection
|
||||
where Base: BidirectionalCollection {
|
||||
@inlinable
|
||||
public func index(before i: Index) -> Index {
|
||||
@@ -160,9 +157,12 @@ extension FiniteCycle: BidirectionalCollection
|
||||
}
|
||||
}
|
||||
|
||||
extension FiniteCycle: RandomAccessCollection
|
||||
extension CycledTimesCollection: RandomAccessCollection
|
||||
where Base: RandomAccessCollection {}
|
||||
|
||||
extension CycledTimesCollection: LazySequenceProtocol, LazyCollectionProtocol
|
||||
where Base: LazySequenceProtocol {}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// cycled()
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -194,8 +194,8 @@ extension Collection {
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@inlinable
|
||||
public func cycled() -> Cycle<Self> {
|
||||
Cycle(base: self)
|
||||
public func cycled() -> CycledSequence<Self> {
|
||||
CycledSequence(base: self)
|
||||
}
|
||||
|
||||
/// Returns a sequence that repeats the elements of this collection the
|
||||
@@ -216,7 +216,7 @@ extension Collection {
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@inlinable
|
||||
public func cycled(times: Int) -> FiniteCycle<Self> {
|
||||
FiniteCycle(base: self, times: times)
|
||||
public func cycled(times: Int) -> CycledTimesCollection<Self> {
|
||||
CycledTimesCollection(base: self, times: times)
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
/// A collection wrapper that iterates over the indices and elements of a
|
||||
/// collection together.
|
||||
public struct Indexed<Base: Collection> {
|
||||
public struct IndexedCollection<Base: Collection> {
|
||||
/// The element type for an `Indexed` collection.
|
||||
public typealias Element = (index: Base.Index, element: Base.Element)
|
||||
|
||||
@@ -25,7 +25,7 @@ public struct Indexed<Base: Collection> {
|
||||
}
|
||||
}
|
||||
|
||||
extension Indexed: Collection {
|
||||
extension IndexedCollection: Collection {
|
||||
@inlinable
|
||||
public var startIndex: Base.Index {
|
||||
base.startIndex
|
||||
@@ -62,16 +62,16 @@ extension Indexed: Collection {
|
||||
}
|
||||
}
|
||||
|
||||
extension Indexed: BidirectionalCollection where Base: BidirectionalCollection {
|
||||
extension IndexedCollection: BidirectionalCollection where Base: BidirectionalCollection {
|
||||
@inlinable
|
||||
public func index(before i: Base.Index) -> Base.Index {
|
||||
base.index(before: i)
|
||||
}
|
||||
}
|
||||
|
||||
extension Indexed: RandomAccessCollection where Base: RandomAccessCollection {}
|
||||
extension Indexed: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
extension Indexed: LazyCollectionProtocol where Base: LazyCollectionProtocol {}
|
||||
extension IndexedCollection: RandomAccessCollection where Base: RandomAccessCollection {}
|
||||
extension IndexedCollection: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
extension IndexedCollection: LazyCollectionProtocol where Base: LazyCollectionProtocol {}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// indexed()
|
||||
@@ -94,7 +94,7 @@ extension Collection {
|
||||
///
|
||||
/// Returns: A collection of paired indices and elements of this collection.
|
||||
@inlinable
|
||||
public func indexed() -> Indexed<Self> {
|
||||
Indexed(base: self)
|
||||
public func indexed() -> IndexedCollection<Self> {
|
||||
IndexedCollection(base: self)
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
/// A sequence that presents the elements of a base sequence of elements
|
||||
/// with a separator between each of those elements.
|
||||
public struct Intersperse<Base: Sequence> {
|
||||
public struct InterspersedSequence<Base: Sequence> {
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
|
||||
@@ -29,7 +29,7 @@ public struct Intersperse<Base: Sequence> {
|
||||
}
|
||||
}
|
||||
|
||||
extension Intersperse: Sequence {
|
||||
extension InterspersedSequence: Sequence {
|
||||
/// The iterator for an `Intersperse` sequence.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
@@ -76,12 +76,12 @@ extension Intersperse: Sequence {
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func makeIterator() -> Intersperse<Base>.Iterator {
|
||||
public func makeIterator() -> InterspersedSequence<Base>.Iterator {
|
||||
Iterator(iterator: base.makeIterator(), separator: separator)
|
||||
}
|
||||
}
|
||||
|
||||
extension Intersperse: Collection where Base: Collection {
|
||||
extension InterspersedSequence: Collection where Base: Collection {
|
||||
/// A position in an `Intersperse` collection.
|
||||
public struct Index: Comparable {
|
||||
@usableFromInline
|
||||
@@ -256,7 +256,7 @@ extension Intersperse: Collection where Base: Collection {
|
||||
}
|
||||
}
|
||||
|
||||
extension Intersperse: BidirectionalCollection
|
||||
extension InterspersedSequence: BidirectionalCollection
|
||||
where Base: BidirectionalCollection
|
||||
{
|
||||
@inlinable
|
||||
@@ -271,13 +271,13 @@ extension Intersperse: BidirectionalCollection
|
||||
}
|
||||
}
|
||||
|
||||
extension Intersperse: RandomAccessCollection
|
||||
extension InterspersedSequence: RandomAccessCollection
|
||||
where Base: RandomAccessCollection {}
|
||||
|
||||
extension Intersperse: LazySequenceProtocol
|
||||
extension InterspersedSequence: LazySequenceProtocol
|
||||
where Base: LazySequenceProtocol {}
|
||||
|
||||
extension Intersperse: LazyCollectionProtocol
|
||||
extension InterspersedSequence: LazyCollectionProtocol
|
||||
where Base: LazyCollectionProtocol {}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -289,7 +289,7 @@ extension Intersperse: LazyCollectionProtocol
|
||||
/// elements, with a separator that separates each pair of adjacent transformed
|
||||
/// values.
|
||||
@usableFromInline
|
||||
internal struct InterspersedMap<Base: Sequence, Result> {
|
||||
internal struct InterspersedMapSequence<Base: Sequence, Result> {
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
|
||||
@@ -300,7 +300,7 @@ internal struct InterspersedMap<Base: Sequence, Result> {
|
||||
internal let separator: (Base.Element, Base.Element) -> Result
|
||||
}
|
||||
|
||||
extension InterspersedMap: Sequence {
|
||||
extension InterspersedMapSequence: Sequence {
|
||||
@usableFromInline
|
||||
internal struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
@@ -360,7 +360,7 @@ extension InterspersedMap: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension InterspersedMap: Collection where Base: Collection {
|
||||
extension InterspersedMapSequence: Collection where Base: Collection {
|
||||
@usableFromInline
|
||||
internal struct Index: Comparable {
|
||||
@usableFromInline
|
||||
@@ -561,7 +561,7 @@ extension InterspersedMap: Collection where Base: Collection {
|
||||
}
|
||||
}
|
||||
|
||||
extension InterspersedMap: BidirectionalCollection
|
||||
extension InterspersedMapSequence: BidirectionalCollection
|
||||
where Base: BidirectionalCollection
|
||||
{
|
||||
@inlinable
|
||||
@@ -577,12 +577,12 @@ extension InterspersedMap: BidirectionalCollection
|
||||
}
|
||||
}
|
||||
|
||||
extension InterspersedMap.Index.Representation: Hashable
|
||||
extension InterspersedMapSequence.Index.Representation: Hashable
|
||||
where Base.Index: Hashable {}
|
||||
|
||||
extension InterspersedMap: LazySequenceProtocol
|
||||
extension InterspersedMapSequence: LazySequenceProtocol
|
||||
where Base: LazySequenceProtocol {}
|
||||
extension InterspersedMap: LazyCollectionProtocol
|
||||
extension InterspersedMapSequence: LazyCollectionProtocol
|
||||
where Base: LazyCollectionProtocol {}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -620,8 +620,8 @@ extension Sequence {
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@inlinable
|
||||
public func interspersed(with separator: Element) -> Intersperse<Self> {
|
||||
Intersperse(base: self, separator: separator)
|
||||
public func interspersed(with separator: Element) -> InterspersedSequence<Self> {
|
||||
InterspersedSequence(base: self, separator: separator)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -647,7 +647,7 @@ extension LazySequenceProtocol {
|
||||
internal func interspersedMap<Result>(
|
||||
_ transform: @escaping (Element) -> Result,
|
||||
with separator: @escaping (Element, Element) -> Result
|
||||
) -> InterspersedMap<Self, Result> {
|
||||
InterspersedMap(base: self, transform: transform, separator: separator)
|
||||
) -> InterspersedMapSequence<Self, Result> {
|
||||
InterspersedMapSequence(base: self, transform: transform, separator: separator)
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,8 @@ public struct JoinedBySequence<Base: Sequence, Separator: Sequence>
|
||||
where Base.Element: Sequence, Base.Element.Element == Separator.Element
|
||||
{
|
||||
@usableFromInline
|
||||
internal typealias Inner = FlattenSequence<
|
||||
Intersperse<LazyMapSequence<Base, EitherSequence<Base.Element, Separator>>>>
|
||||
internal typealias Inner = FlattenSequence<InterspersedSequence<
|
||||
LazyMapSequence<Base, EitherSequence<Base.Element, Separator>>>>
|
||||
|
||||
@usableFromInline
|
||||
internal let inner: Inner
|
||||
@@ -70,8 +70,8 @@ public struct JoinedByClosureSequence<Base: Sequence, Separator: Sequence>
|
||||
where Base.Element: Sequence, Base.Element.Element == Separator.Element
|
||||
{
|
||||
@usableFromInline
|
||||
internal typealias Inner = FlattenSequence<
|
||||
InterspersedMap<LazySequence<Base>, EitherSequence<Base.Element, Separator>>>
|
||||
internal typealias Inner = FlattenSequence<InterspersedMapSequence<
|
||||
LazySequence<Base>, EitherSequence<Base.Element, Separator>>>
|
||||
|
||||
@usableFromInline
|
||||
internal let inner: Inner
|
||||
@@ -124,8 +124,8 @@ public struct JoinedByCollection<Base: Collection, Separator: Collection>
|
||||
where Base.Element: Collection, Base.Element.Element == Separator.Element
|
||||
{
|
||||
@usableFromInline
|
||||
internal typealias Inner = FlattenCollection<
|
||||
Intersperse<LazyMapSequence<Base, EitherSequence<Base.Element, Separator>>>>
|
||||
internal typealias Inner = FlattenCollection<InterspersedSequence<
|
||||
LazyMapSequence<Base, EitherSequence<Base.Element, Separator>>>>
|
||||
|
||||
@usableFromInline
|
||||
internal let inner: Inner
|
||||
@@ -228,8 +228,8 @@ public struct JoinedByClosureCollection<Base: Collection, Separator: Collection>
|
||||
where Base.Element: Collection, Base.Element.Element == Separator.Element
|
||||
{
|
||||
@usableFromInline
|
||||
internal typealias Inner = FlattenCollection<
|
||||
InterspersedMap<LazySequence<Base>, EitherSequence<Base.Element, Separator>>>
|
||||
internal typealias Inner = FlattenCollection<InterspersedMapSequence<
|
||||
LazySequence<Base>, EitherSequence<Base.Element, Separator>>>
|
||||
|
||||
@usableFromInline
|
||||
internal let inner: Inner
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
/// x.split(separator:maxSplits:omittingEmptySubsequences)
|
||||
///
|
||||
/// where `x` conforms to `LazySequenceProtocol`.
|
||||
public struct LazySplitSequence<Base: Sequence> {
|
||||
public struct SplitSequence<Base: Sequence> {
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
|
||||
@@ -48,7 +48,7 @@ public struct LazySplitSequence<Base: Sequence> {
|
||||
}
|
||||
}
|
||||
|
||||
extension LazySplitSequence {
|
||||
extension SplitSequence {
|
||||
public struct Iterator {
|
||||
public typealias Element = [Base.Element]
|
||||
|
||||
@@ -87,7 +87,7 @@ extension LazySplitSequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension LazySplitSequence.Iterator: IteratorProtocol {
|
||||
extension SplitSequence.Iterator: IteratorProtocol {
|
||||
@inlinable
|
||||
public mutating func next() -> Element? {
|
||||
var currentElement = base.next()
|
||||
@@ -128,7 +128,7 @@ extension LazySplitSequence.Iterator: IteratorProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
extension LazySplitSequence: LazySequenceProtocol {
|
||||
extension SplitSequence: LazySequenceProtocol {
|
||||
@inlinable
|
||||
public func makeIterator() -> Iterator {
|
||||
return Iterator(
|
||||
@@ -230,10 +230,10 @@ extension LazySequenceProtocol {
|
||||
maxSplits: Int = Int.max,
|
||||
omittingEmptySubsequences: Bool = true,
|
||||
whereSeparator isSeparator: @escaping (Element) -> Bool
|
||||
) -> LazySplitSequence<Elements> {
|
||||
) -> SplitSequence<Elements> {
|
||||
precondition(maxSplits >= 0, "Must take zero or more splits")
|
||||
|
||||
return LazySplitSequence(
|
||||
return SplitSequence(
|
||||
base: elements,
|
||||
isSeparator: isSeparator,
|
||||
maxSplits: maxSplits,
|
||||
@@ -320,10 +320,10 @@ extension LazySequenceProtocol where Element: Equatable {
|
||||
separator: Element,
|
||||
maxSplits: Int = Int.max,
|
||||
omittingEmptySubsequences: Bool = true
|
||||
) -> LazySplitSequence<Elements> {
|
||||
) -> SplitSequence<Elements> {
|
||||
precondition(maxSplits >= 0, "Must take zero or more splits")
|
||||
|
||||
return LazySplitSequence(
|
||||
return SplitSequence(
|
||||
base: elements,
|
||||
isSeparator: { $0 == separator },
|
||||
maxSplits: maxSplits,
|
||||
@@ -344,7 +344,7 @@ extension LazySequenceProtocol where Element: Equatable {
|
||||
/// x.split(separator:maxSplits:omittingEmptySubsequences)
|
||||
///
|
||||
/// where `x` conforms to `LazyCollectionProtocol`.
|
||||
public struct LazySplitCollection<Base: Collection> {
|
||||
public struct SplitCollection<Base: Collection> {
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
|
||||
@@ -398,7 +398,7 @@ public struct LazySplitCollection<Base: Collection> {
|
||||
}
|
||||
}
|
||||
|
||||
extension LazySplitCollection: LazyCollectionProtocol {
|
||||
extension SplitCollection: LazyCollectionProtocol {
|
||||
/// Position of a subsequence in a split collection.
|
||||
public struct Index: Comparable {
|
||||
/// The range corresponding to the subsequence at this position.
|
||||
@@ -547,7 +547,7 @@ extension LazySplitCollection: LazyCollectionProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
extension LazySplitCollection.Index: Hashable {
|
||||
extension SplitCollection.Index: Hashable {
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(sequenceLength)
|
||||
}
|
||||
@@ -641,10 +641,10 @@ extension LazyCollectionProtocol {
|
||||
maxSplits: Int = Int.max,
|
||||
omittingEmptySubsequences: Bool = true,
|
||||
whereSeparator isSeparator: @escaping (Element) -> Bool
|
||||
) -> LazySplitCollection<Elements> {
|
||||
) -> SplitCollection<Elements> {
|
||||
precondition(maxSplits >= 0, "Must take zero or more splits")
|
||||
|
||||
return LazySplitCollection(
|
||||
return SplitCollection(
|
||||
base: elements,
|
||||
isSeparator: isSeparator,
|
||||
maxSplits: maxSplits,
|
||||
@@ -737,10 +737,10 @@ where Element: Equatable {
|
||||
separator: Element,
|
||||
maxSplits: Int = Int.max,
|
||||
omittingEmptySubsequences: Bool = true
|
||||
) -> LazySplitCollection<Elements> {
|
||||
) -> SplitCollection<Elements> {
|
||||
precondition(maxSplits >= 0, "Must take zero or more splits")
|
||||
|
||||
return LazySplitCollection(
|
||||
return SplitCollection(
|
||||
base: elements,
|
||||
isSeparator: { $0 == separator },
|
||||
maxSplits: maxSplits,
|
||||
|
||||
@@ -76,7 +76,7 @@ extension MutableCollection
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A sequence of all the permutations of a collection's elements.
|
||||
public struct Permutations<Base: Collection> {
|
||||
public struct PermutationsSequence<Base: Collection> {
|
||||
/// The base collection to iterate over for permutations.
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
@@ -134,7 +134,7 @@ public struct Permutations<Base: Collection> {
|
||||
}
|
||||
}
|
||||
|
||||
extension Permutations: Sequence {
|
||||
extension PermutationsSequence: Sequence {
|
||||
/// The iterator for a `Permutations` instance.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
@@ -160,7 +160,7 @@ extension Permutations: Sequence {
|
||||
internal var indexes: [Base.Index]
|
||||
|
||||
@inlinable
|
||||
internal init(_ permutations: Permutations) {
|
||||
internal init(_ permutations: PermutationsSequence) {
|
||||
self.base = permutations.base
|
||||
self.baseCount = permutations.baseCount
|
||||
self.kRange = permutations.kRange
|
||||
@@ -259,7 +259,7 @@ extension Permutations: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension Permutations: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
extension PermutationsSequence: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// permutations(ofCount:)
|
||||
@@ -325,8 +325,8 @@ extension Collection {
|
||||
@inlinable
|
||||
public func permutations<R: RangeExpression>(
|
||||
ofCount kRange: R
|
||||
) -> Permutations<Self> where R.Bound == Int {
|
||||
return Permutations(self, kRange: kRange)
|
||||
) -> PermutationsSequence<Self> where R.Bound == Int {
|
||||
return PermutationsSequence(self, kRange: kRange)
|
||||
}
|
||||
|
||||
/// Returns a collection of the permutations of this collection of the
|
||||
@@ -379,11 +379,11 @@ extension Collection {
|
||||
/// is the number of elements in the base collection, since `Permutations`
|
||||
/// accesses the `count` of the base collection.
|
||||
@inlinable
|
||||
public func permutations(ofCount k: Int? = nil) -> Permutations<Self> {
|
||||
public func permutations(ofCount k: Int? = nil) -> PermutationsSequence<Self> {
|
||||
precondition(
|
||||
k ?? 0 >= 0,
|
||||
"Can't have permutations with a negative number of elements.")
|
||||
return Permutations(self, k: k)
|
||||
return PermutationsSequence(self, k: k)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ extension Collection {
|
||||
///
|
||||
/// To create a `UniquePermutations` instance, call one of the
|
||||
/// `uniquePermutations` methods on your collection.
|
||||
public struct UniquePermutations<Base: Collection> {
|
||||
public struct UniquePermutationsSequence<Base: Collection> {
|
||||
/// The base collection to iterate over for permutations.
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
@@ -408,7 +408,7 @@ public struct UniquePermutations<Base: Collection> {
|
||||
internal let kRange: Range<Int>
|
||||
}
|
||||
|
||||
extension UniquePermutations where Base.Element: Hashable {
|
||||
extension UniquePermutationsSequence where Base.Element: Hashable {
|
||||
@inlinable
|
||||
internal static func _indexes(_ base: Base) -> [Base.Index] {
|
||||
let firstIndexesAndCountsByElement = Dictionary(
|
||||
@@ -440,7 +440,7 @@ extension UniquePermutations where Base.Element: Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
extension UniquePermutations: Sequence {
|
||||
extension UniquePermutationsSequence: Sequence {
|
||||
/// The iterator for a `UniquePermutations` instance.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
@@ -496,7 +496,7 @@ extension UniquePermutations: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension UniquePermutations: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
extension UniquePermutationsSequence: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
|
||||
extension Collection where Element: Hashable {
|
||||
/// Returns a sequence of the unique permutations of this sequence of the
|
||||
@@ -537,11 +537,11 @@ extension Collection where Element: Hashable {
|
||||
///
|
||||
/// - Complexity: O(*n*), where *n* is the number of elements in this
|
||||
/// collection.
|
||||
public func uniquePermutations(ofCount k: Int? = nil) -> UniquePermutations<Self> {
|
||||
public func uniquePermutations(ofCount k: Int? = nil) -> UniquePermutationsSequence<Self> {
|
||||
if let k = k {
|
||||
return UniquePermutations(self, k ..< (k + 1))
|
||||
return UniquePermutationsSequence(self, k ..< (k + 1))
|
||||
} else {
|
||||
return UniquePermutations(self)
|
||||
return UniquePermutationsSequence(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,9 +574,9 @@ extension Collection where Element: Hashable {
|
||||
///
|
||||
/// - Complexity: O(*n*), where *n* is the number of elements in this
|
||||
/// collection.
|
||||
public func uniquePermutations<R: RangeExpression>(ofCount kRange: R) -> UniquePermutations<Self>
|
||||
public func uniquePermutations<R: RangeExpression>(ofCount kRange: R) -> UniquePermutationsSequence<Self>
|
||||
where R.Bound == Int
|
||||
{
|
||||
UniquePermutations(self, kRange)
|
||||
UniquePermutationsSequence(self, kRange)
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A sequence that represents the product of two sequences' elements.
|
||||
public struct Product2<Base1: Sequence, Base2: Collection> {
|
||||
public struct Product2Sequence<Base1: Sequence, Base2: Collection> {
|
||||
/// The outer sequence in the product.
|
||||
@usableFromInline
|
||||
internal let base1: Base1
|
||||
@@ -26,7 +26,7 @@ public struct Product2<Base1: Sequence, Base2: Collection> {
|
||||
}
|
||||
}
|
||||
|
||||
extension Product2: Sequence {
|
||||
extension Product2Sequence: Sequence {
|
||||
public typealias Element = (Base1.Element, Base2.Element)
|
||||
|
||||
/// The iterator for a `Product2` sequence.
|
||||
@@ -41,7 +41,7 @@ extension Product2: Sequence {
|
||||
internal let base2: Base2
|
||||
|
||||
@inlinable
|
||||
internal init(_ c: Product2) {
|
||||
internal init(_ c: Product2Sequence) {
|
||||
self.base2 = c.base2
|
||||
self.i1 = c.base1.makeIterator()
|
||||
self.i2 = c.base2.makeIterator()
|
||||
@@ -88,7 +88,7 @@ extension Product2: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension Product2: Collection where Base1: Collection {
|
||||
extension Product2Sequence: Collection where Base1: Collection {
|
||||
/// The index type for a `Product2` collection.
|
||||
public struct Index: Comparable {
|
||||
@usableFromInline
|
||||
@@ -419,7 +419,7 @@ extension Product2: Collection where Base1: Collection {
|
||||
}
|
||||
}
|
||||
|
||||
extension Product2: BidirectionalCollection
|
||||
extension Product2Sequence: BidirectionalCollection
|
||||
where Base1: BidirectionalCollection, Base2: BidirectionalCollection
|
||||
{
|
||||
@inlinable
|
||||
@@ -436,10 +436,10 @@ extension Product2: BidirectionalCollection
|
||||
}
|
||||
}
|
||||
|
||||
extension Product2: RandomAccessCollection
|
||||
extension Product2Sequence: RandomAccessCollection
|
||||
where Base1: RandomAccessCollection, Base2: RandomAccessCollection {}
|
||||
|
||||
extension Product2.Index: Hashable where Base1.Index: Hashable, Base2.Index: Hashable {}
|
||||
extension Product2Sequence.Index: Hashable where Base1.Index: Hashable, Base2.Index: Hashable {}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// product(_:_:)
|
||||
@@ -481,6 +481,6 @@ extension Product2.Index: Hashable where Base1.Index: Hashable, Base2.Index: Has
|
||||
@inlinable
|
||||
public func product<Base1: Sequence, Base2: Collection>(
|
||||
_ s1: Base1, _ s2: Base2
|
||||
) -> Product2<Base1, Base2> {
|
||||
return Product2(s1, s2)
|
||||
) -> Product2Sequence<Base1, Base2> {
|
||||
return Product2Sequence(s1, s2)
|
||||
}
|
||||
@@ -38,7 +38,7 @@ extension LazySequenceProtocol {
|
||||
public func reductions<Result>(
|
||||
_ initial: Result,
|
||||
_ transform: @escaping (Result, Element) -> Result
|
||||
) -> ExclusiveReductions<Result, Self> {
|
||||
) -> ExclusiveReductionsSequence<Result, Self> {
|
||||
return reductions(into: initial) { result, element in
|
||||
result = transform(result, element)
|
||||
}
|
||||
@@ -69,8 +69,8 @@ extension LazySequenceProtocol {
|
||||
public func reductions<Result>(
|
||||
into initial: Result,
|
||||
_ transform: @escaping (inout Result, Element) -> Void
|
||||
) -> ExclusiveReductions<Result, Self> {
|
||||
ExclusiveReductions(base: self, initial: initial, transform: transform)
|
||||
) -> ExclusiveReductionsSequence<Result, Self> {
|
||||
ExclusiveReductionsSequence(base: self, initial: initial, transform: transform)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ extension Sequence {
|
||||
|
||||
/// A sequence of applying a transform to the element of a sequence and the
|
||||
/// previously transformed result.
|
||||
public struct ExclusiveReductions<Result, Base: Sequence> {
|
||||
public struct ExclusiveReductionsSequence<Result, Base: Sequence> {
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
|
||||
@@ -198,7 +198,7 @@ public struct ExclusiveReductions<Result, Base: Sequence> {
|
||||
}
|
||||
}
|
||||
|
||||
extension ExclusiveReductions: Sequence {
|
||||
extension ExclusiveReductionsSequence: Sequence {
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
internal var iterator: Base.Iterator
|
||||
@@ -240,7 +240,7 @@ extension ExclusiveReductions: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension ExclusiveReductions: Collection where Base: Collection {
|
||||
extension ExclusiveReductionsSequence: Collection where Base: Collection {
|
||||
public struct Index: Comparable {
|
||||
@usableFromInline
|
||||
internal let representation: ReductionsIndexRepresentation<Base.Index, Result>
|
||||
@@ -316,10 +316,10 @@ extension ExclusiveReductions: Collection where Base: Collection {
|
||||
}
|
||||
}
|
||||
|
||||
extension ExclusiveReductions: LazySequenceProtocol
|
||||
extension ExclusiveReductionsSequence: LazySequenceProtocol
|
||||
where Base: LazySequenceProtocol {}
|
||||
|
||||
extension ExclusiveReductions: LazyCollectionProtocol
|
||||
extension ExclusiveReductionsSequence: LazyCollectionProtocol
|
||||
where Base: LazyCollectionProtocol {}
|
||||
|
||||
// MARK: - Inclusive Reductions
|
||||
@@ -348,8 +348,8 @@ extension LazySequenceProtocol {
|
||||
@inlinable
|
||||
public func reductions(
|
||||
_ transform: @escaping (Element, Element) -> Element
|
||||
) -> InclusiveReductions<Self> {
|
||||
InclusiveReductions(base: self, transform: transform)
|
||||
) -> InclusiveReductionsSequence<Self> {
|
||||
InclusiveReductionsSequence(base: self, transform: transform)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ extension Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
public struct InclusiveReductions<Base: Sequence> {
|
||||
public struct InclusiveReductionsSequence<Base: Sequence> {
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
|
||||
@@ -417,7 +417,7 @@ public struct InclusiveReductions<Base: Sequence> {
|
||||
}
|
||||
}
|
||||
|
||||
extension InclusiveReductions: Sequence {
|
||||
extension InclusiveReductionsSequence: Sequence {
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
internal var iterator: Base.Iterator
|
||||
@@ -458,7 +458,7 @@ extension InclusiveReductions: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension InclusiveReductions: Collection where Base: Collection {
|
||||
extension InclusiveReductionsSequence: Collection where Base: Collection {
|
||||
public struct Index: Comparable {
|
||||
@usableFromInline
|
||||
internal let representation: ReductionsIndexRepresentation<Base.Index, Base.Element>
|
||||
@@ -536,10 +536,10 @@ extension InclusiveReductions: Collection where Base: Collection {
|
||||
}
|
||||
}
|
||||
|
||||
extension InclusiveReductions: LazySequenceProtocol
|
||||
extension InclusiveReductionsSequence: LazySequenceProtocol
|
||||
where Base: LazySequenceProtocol {}
|
||||
|
||||
extension InclusiveReductions: LazyCollectionProtocol
|
||||
extension InclusiveReductionsSequence: LazyCollectionProtocol
|
||||
where Base: LazyCollectionProtocol {}
|
||||
|
||||
// MARK: - ReductionsIndexRepresentation
|
||||
@@ -585,7 +585,7 @@ extension LazySequenceProtocol {
|
||||
public func scan<Result>(
|
||||
_ initial: Result,
|
||||
_ transform: @escaping (Result, Element) -> Result
|
||||
) -> ExclusiveReductions<Result, Self> {
|
||||
) -> ExclusiveReductionsSequence<Result, Self> {
|
||||
reductions(initial, transform)
|
||||
}
|
||||
|
||||
@@ -594,7 +594,7 @@ extension LazySequenceProtocol {
|
||||
public func scan<Result>(
|
||||
into initial: Result,
|
||||
_ transform: @escaping (inout Result, Element) -> Void
|
||||
) -> ExclusiveReductions<Result, Self> {
|
||||
) -> ExclusiveReductionsSequence<Result, Self> {
|
||||
reductions(into: initial, transform)
|
||||
}
|
||||
}
|
||||
@@ -626,7 +626,7 @@ extension LazySequenceProtocol {
|
||||
@inlinable
|
||||
public func scan(
|
||||
_ transform: @escaping (Element, Element) -> Element
|
||||
) -> InclusiveReductions<Self> {
|
||||
) -> InclusiveReductionsSequence<Self> {
|
||||
reductions(transform)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ extension Sequence {
|
||||
/// - Returns: Returns a sequence for stepping through the
|
||||
/// elements by the specified amount.
|
||||
@inlinable
|
||||
public func striding(by step: Int) -> StrideSequence<Self> {
|
||||
StrideSequence(base: self, stride: step)
|
||||
public func striding(by step: Int) -> StridingSequence<Self> {
|
||||
StridingSequence(base: self, stride: step)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,13 +47,13 @@ extension Collection {
|
||||
/// - Returns: Returns a collection for stepping through the
|
||||
/// elements by the specified amount.
|
||||
@inlinable
|
||||
public func striding(by step: Int) -> StrideCollection<Self> {
|
||||
StrideCollection(base: self, stride: step)
|
||||
public func striding(by step: Int) -> StridingCollection<Self> {
|
||||
StridingCollection(base: self, stride: step)
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper that strides over a base sequence.
|
||||
public struct StrideSequence<Base: Sequence>: Sequence {
|
||||
public struct StridingSequence<Base: Sequence>: Sequence {
|
||||
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
@@ -69,7 +69,7 @@ public struct StrideSequence<Base: Sequence>: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension StrideSequence {
|
||||
extension StridingSequence {
|
||||
|
||||
/// An iterator over a `Stride` sequence.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@@ -107,7 +107,7 @@ extension StrideSequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension StrideSequence {
|
||||
extension StridingSequence {
|
||||
@inlinable
|
||||
public func striding(by step: Int) -> Self {
|
||||
Self(base: base, stride: stride * step)
|
||||
@@ -115,7 +115,7 @@ extension StrideSequence {
|
||||
}
|
||||
|
||||
/// A wrapper that strides over a base collection.
|
||||
public struct StrideCollection<Base: Collection> {
|
||||
public struct StridingCollection<Base: Collection> {
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
|
||||
@@ -130,14 +130,14 @@ public struct StrideCollection<Base: Collection> {
|
||||
}
|
||||
}
|
||||
|
||||
extension StrideCollection {
|
||||
extension StridingCollection {
|
||||
@inlinable
|
||||
public func striding(by step: Int) -> Self {
|
||||
Self(base: base, stride: stride * step)
|
||||
}
|
||||
}
|
||||
|
||||
extension StrideCollection: Collection {
|
||||
extension StridingCollection: Collection {
|
||||
|
||||
/// A position in a `Stride` collection.
|
||||
public struct Index: Comparable {
|
||||
@@ -264,7 +264,7 @@ extension StrideCollection: Collection {
|
||||
}
|
||||
}
|
||||
|
||||
extension StrideCollection: BidirectionalCollection
|
||||
extension StridingCollection: BidirectionalCollection
|
||||
where Base: RandomAccessCollection {
|
||||
|
||||
@inlinable
|
||||
@@ -274,5 +274,5 @@ extension StrideCollection: BidirectionalCollection
|
||||
}
|
||||
}
|
||||
|
||||
extension StrideCollection: RandomAccessCollection where Base: RandomAccessCollection {}
|
||||
extension StrideCollection.Index: Hashable where Base.Index: Hashable {}
|
||||
extension StridingCollection: RandomAccessCollection where Base: RandomAccessCollection {}
|
||||
extension StridingCollection.Index: Hashable where Base.Index: Hashable {}
|
||||
@@ -10,7 +10,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A sequence wrapper that leaves out duplicate elements of a base sequence.
|
||||
public struct Uniqued<Base: Sequence, Subject: Hashable> {
|
||||
public struct UniquedSequence<Base: Sequence, Subject: Hashable> {
|
||||
/// The base collection.
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
@@ -26,7 +26,7 @@ public struct Uniqued<Base: Sequence, Subject: Hashable> {
|
||||
}
|
||||
}
|
||||
|
||||
extension Uniqued: Sequence {
|
||||
extension UniquedSequence: Sequence {
|
||||
/// The iterator for a `Uniqued` sequence.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
@@ -64,7 +64,8 @@ extension Uniqued: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension Uniqued: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
extension UniquedSequence: LazySequenceProtocol
|
||||
where Base: LazySequenceProtocol {}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// uniqued()
|
||||
@@ -83,8 +84,8 @@ extension Sequence where Element: Hashable {
|
||||
/// .
|
||||
/// - Complexity: O(1).
|
||||
@inlinable
|
||||
public func uniqued() -> Uniqued<Self, Element> {
|
||||
Uniqued(base: self, projection: { $0 })
|
||||
public func uniqued() -> UniquedSequence<Self, Element> {
|
||||
UniquedSequence(base: self, projection: { $0 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +139,7 @@ extension LazySequenceProtocol {
|
||||
@inlinable
|
||||
public func uniqued<Subject: Hashable>(
|
||||
on projection: @escaping (Element) -> Subject
|
||||
) -> Uniqued<Self, Subject> {
|
||||
Uniqued(base: self, projection: projection)
|
||||
) -> UniquedSequence<Self, Subject> {
|
||||
UniquedSequence(base: self, projection: projection)
|
||||
}
|
||||
}
|
||||
@@ -39,14 +39,14 @@ extension Collection {
|
||||
/// `RandomAccessCollection`, otherwise O(*k*) where `k` is `count`.
|
||||
/// Access to successive windows is O(1).
|
||||
@inlinable
|
||||
public func windows(ofCount count: Int) -> Windows<Self> {
|
||||
Windows(base: self, size: count)
|
||||
public func windows(ofCount count: Int) -> WindowsCollection<Self> {
|
||||
WindowsCollection(base: self, size: count)
|
||||
}
|
||||
}
|
||||
|
||||
/// A collection wrapper that presents a sliding window over the elements of
|
||||
/// a collection.
|
||||
public struct Windows<Base: Collection> {
|
||||
public struct WindowsCollection<Base: Collection> {
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
|
||||
@@ -66,7 +66,7 @@ public struct Windows<Base: Collection> {
|
||||
}
|
||||
}
|
||||
|
||||
extension Windows: Collection {
|
||||
extension WindowsCollection: Collection {
|
||||
/// A position in a `Windows` collection.
|
||||
public struct Index: Comparable {
|
||||
@usableFromInline
|
||||
@@ -329,7 +329,7 @@ extension Windows: Collection {
|
||||
}
|
||||
}
|
||||
|
||||
extension Windows: BidirectionalCollection where Base: BidirectionalCollection {
|
||||
extension WindowsCollection: BidirectionalCollection where Base: BidirectionalCollection {
|
||||
@inlinable
|
||||
public func index(before index: Index) -> Index {
|
||||
precondition(index > startIndex, "Incrementing past start index")
|
||||
@@ -347,7 +347,7 @@ extension Windows: BidirectionalCollection where Base: BidirectionalCollection {
|
||||
}
|
||||
}
|
||||
|
||||
extension Windows: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
extension Windows: LazyCollectionProtocol where Base: LazyCollectionProtocol {}
|
||||
extension Windows: RandomAccessCollection where Base: RandomAccessCollection {}
|
||||
extension Windows.Index: Hashable where Base.Index: Hashable {}
|
||||
extension WindowsCollection: LazySequenceProtocol where Base: LazySequenceProtocol {}
|
||||
extension WindowsCollection: LazyCollectionProtocol where Base: LazyCollectionProtocol {}
|
||||
extension WindowsCollection: RandomAccessCollection where Base: RandomAccessCollection {}
|
||||
extension WindowsCollection.Index: Hashable where Base.Index: Hashable {}
|
||||
Reference in new issue
Block a user