mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-26 04:27:48 +00:00
Add LazySequenceProtocol to StridingSequence, StridingCollection
This commit is contained in:
1 parent
859e4bbab2
commit
b6c1da00bb
2 files changed
+13
-1
No files matched your search
@@ -112,6 +112,9 @@ extension StridingSequence: Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension StridingSequence: LazySequenceProtocol
|
||||
where Base: LazySequenceProtocol {}
|
||||
|
||||
/// A wrapper that strides over a base collection.
|
||||
public struct StridingCollection<Base: Collection> {
|
||||
@usableFromInline
|
||||
@@ -273,4 +276,8 @@ extension StridingCollection: BidirectionalCollection
|
||||
|
||||
extension StridingCollection: RandomAccessCollection
|
||||
where Base: RandomAccessCollection {}
|
||||
|
||||
extension StridingCollection: LazySequenceProtocol, LazyCollectionProtocol
|
||||
where Base: LazySequenceProtocol {}
|
||||
|
||||
extension StridingCollection.Index: Hashable where Base.Index: Hashable {}
|
||||
@@ -119,7 +119,6 @@ final class StridingTests: XCTestCase {
|
||||
validator.validate(string.striding(by: 10))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func testOffsetBy() {
|
||||
let a = (0...100).striding(by: 22)
|
||||
@@ -135,4 +134,10 @@ final class StridingTests: XCTestCase {
|
||||
let i = b.index(b.startIndex, offsetBy: 2)
|
||||
XCTAssertEqual(i, b.endIndex)
|
||||
}
|
||||
|
||||
func testLazy() {
|
||||
XCTAssertLazySequence(AnySequence(0..<100).lazy.striding(by: 3))
|
||||
XCTAssertLazySequence((0..<100).lazy.striding(by: 3))
|
||||
XCTAssertLazyCollection((0..<100).lazy.striding(by: 3))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user