Skip to content

Instantly share code, notes, and snippets.

@Tony-Y
Created April 21, 2018 08:56
Show Gist options
  • Save Tony-Y/c39ecb54ad71f2a70b174dcd36aa09a3 to your computer and use it in GitHub Desktop.
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
// 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)
}
@Tony-Y
Copy link
Author

Tony-Y commented Apr 21, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment