Skip to content

Commit f624ba9

Browse files
committed
Add conditional lazy conformances
1 parent 7be7d17 commit f624ba9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Sources/Algorithms/AdjacentPairs.swift

+8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public struct AdjacentPairsSequence<Base: Sequence> {
6969
}
7070

7171
extension AdjacentPairsSequence {
72+
/// The iterator for an `AdjacentPairsSequence` or `AdjacentPairsCollection`.
7273
public struct Iterator {
7374
@usableFromInline
7475
internal var base: Base.Iterator
@@ -113,6 +114,9 @@ extension AdjacentPairsSequence: Sequence {
113114
}
114115
}
115116

117+
extension AdjacentPairsSequence: LazySequenceProtocol
118+
where Base: LazySequenceProtocol {}
119+
116120
/// A collection of adjacent pairs of elements built from an underlying
117121
/// collection.
118122
///
@@ -159,6 +163,7 @@ extension AdjacentPairsCollection {
159163
}
160164

161165
extension AdjacentPairsCollection {
166+
/// A position in an `AdjacentPairsCollection`.
162167
public struct Index: Comparable {
163168
@usableFromInline
164169
internal var first: Base.Index
@@ -299,6 +304,9 @@ extension AdjacentPairsCollection: BidirectionalCollection
299304
extension AdjacentPairsCollection: RandomAccessCollection
300305
where Base: RandomAccessCollection {}
301306

307+
extension AdjacentPairsCollection: LazySequenceProtocol, LazyCollectionProtocol
308+
where Base: LazyCollectionProtocol {}
309+
302310
extension AdjacentPairsCollection.Index: Hashable where Base.Index: Hashable {
303311
@inlinable
304312
public func hash(into hasher: inout Hasher) {

Tests/SwiftAlgorithmsTests/AdjacentPairsTests.swift

+5
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,9 @@ final class AdjacentPairsTests: XCTestCase {
7272
func testIndexTraversals() {
7373
validateIndexTraversals((1...5).adjacentPairs())
7474
}
75+
76+
func testLaziness() {
77+
XCTAssertLazySequence((0...).lazy.adjacentPairs())
78+
XCTAssertLazyCollection((0..<100).lazy.adjacentPairs())
79+
}
7580
}

0 commit comments

Comments
 (0)