Skip to content

Commit e69f9a6

Browse files
committed
Manually implement All functionality
CountableRange.Iterator returns 0 for underestimatedCount, which is kind of useless to us.
1 parent 39d3ec7 commit e69f9a6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/Hexe/All.swift

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@ public protocol AllIterable {
1515
/// An iterator over all instances of `T`.
1616
public struct All<T: AllIterable>: IteratorProtocol, Sequence {
1717

18-
private var iter: CountableRange<UInt8>.Iterator
18+
private var current: UInt8 = 0
19+
20+
private let total: UInt8
1921

2022
public var underestimatedCount: Int {
21-
return self.iter.underestimatedCount
23+
return Range(uncheckedBounds: (current, total)).count
2224
}
2325

2426
fileprivate init(_ total: UInt8) {
25-
self.iter = (0 ..< total).makeIterator()
27+
self.total = total
2628
}
2729

2830
public mutating func next() -> T? {
29-
guard let next = self.iter.next() else {
31+
guard self.current < self.total else {
3032
return nil
3133
}
34+
let next = self.current
35+
self.current = next &+ 1
3236
return unsafeBitCast(next, to: T.self)
3337
}
3438

0 commit comments

Comments
 (0)