Skip to content

Commit 19d0026

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

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Sources/Algorithms/AdjacentPairs.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ extension AdjacentPairsSequence: Sequence {
113113
}
114114
}
115115

116+
extension AdjacentPairsSequence: LazySequenceProtocol
117+
where Base: LazySequenceProtocol {}
118+
116119
/// A collection of adjacent pairs of elements built from an underlying
117120
/// collection.
118121
///
@@ -299,6 +302,9 @@ extension AdjacentPairsCollection: BidirectionalCollection
299302
extension AdjacentPairsCollection: RandomAccessCollection
300303
where Base: RandomAccessCollection {}
301304

305+
extension AdjacentPairsCollection: LazySequenceProtocol, LazyCollectionProtocol
306+
where Base: LazyCollectionProtocol {}
307+
302308
extension AdjacentPairsCollection.Index: Hashable where Base.Index: Hashable {
303309
@inlinable
304310
public func hash(into hasher: inout Hasher) {

Tests/SwiftAlgorithmsTests/AdjacentPairsTests.swift

Lines changed: 5 additions & 0 deletions
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)