Created
April 15, 2022 20:56
-
-
Save Losiowaty/cb492702d30f610e9c7a7269396aa4cf to your computer and use it in GitHub Desktop.
Stride that Range
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func stride<Bound: Comparable & Strideable>(range: ClosedRange<Bound>, by: Bound.Stride) -> StrideThrough<Bound> { | |
| stride(from: range.lowerBound, through: range.upperBound, by: by) | |
| } | |
| func stride<Bound: Comparable & Strideable>(range: Range<Bound>, by: Bound.Stride) -> StrideTo<Bound> { | |
| stride(from: range.lowerBound, to: range.upperBound, by: by) | |
| } | |
| //for _ in 0...999_999 { | |
| // let lowerBound = Int.random(in: 0...100) | |
| // let upperBound = Int.random(in: 100_000...999_999) | |
| // let by = Int.random(in: 1...256_512) | |
| // | |
| // let rangeStride = stride(range: lowerBound...upperBound, by: by) | |
| // let directStride = stride(from: lowerBound, through: upperBound, by: by) | |
| // | |
| // if rangeStride.map { $0 } != directStride.map { $0 } { | |
| // print("FAILURE FOR CLOSED RANGE") | |
| // print("lowerBound == \(lowerBound)") | |
| // print("upperBound == \(upperBound)") | |
| // print("by == \(by)") | |
| // } | |
| //} | |
| // | |
| //for _ in 0...999_999 { | |
| // let lowerBound = Int.random(in: 0...100) | |
| // let upperBound = Int.random(in: 100_000...999_999) | |
| // let by = Int.random(in: 1...256_512) | |
| // | |
| // let rangeStride = stride(range: lowerBound..<upperBound, by: by) | |
| // let directStride = stride(from: lowerBound, to: upperBound, by: by) | |
| // | |
| // if rangeStride.map { $0 } != directStride.map { $0 } { | |
| // print("FAILURE FOR OPEN RANGE") | |
| // print("lowerBound == \(lowerBound)") | |
| // print("upperBound == \(upperBound)") | |
| // print("by == \(by)") | |
| // } | |
| //} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment