Created
April 21, 2018 08:56
-
-
Save Tony-Y/c39ecb54ad71f2a70b174dcd36aa09a3 to your computer and use it in GitHub Desktop.
Swift Stride Operator, e.g. (0..<10)/2 and (0...10)/2
This file contains 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
// Open Range Stride | |
func / <T: Strideable>(left: Range<T>, right: T.Stride) -> StrideTo<T> { | |
return stride(from: left.lowerBound, to: left.upperBound, by: right) | |
} | |
// Closed Range Stride | |
func / <T: Strideable>(left: ClosedRange<T>, right: T.Stride) -> StrideThrough<T> { | |
return stride(from: left.lowerBound, through: left.upperBound, by: right) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can create StrideTo instances by using the stride-to operator (a..<b)/c, and StrideThrough instances by using the stride-through operator (a...b)/c.