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
import Python | |
// Slice Operators | |
precedencegroup SliceFormationPrecedence { | |
associativity: left | |
lowerThan: AdditionPrecedence | |
} | |
infix operator .~: SliceFormationPrecedence | |
prefix operator .~ |
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
struct ArraySliceWithStride<Element> { | |
typealias Base = Array<Element> | |
private let _base: Base | |
private let _slice: Array<Any>.Slice | |
private var _start: Int { return _slice.start! } | |
let count: Int | |
private var _stride: Int { return _slice.stride } | |
init(_ base: Base, from start: Base.Index?, to end: Base.Index?, by stride: Base.Index.Stride) { | |
self._base = base |
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
struct StrideIterator<Element : Strideable> { | |
var element: Element | |
let step: Element.Stride | |
} | |
extension StrideIterator : IteratorProtocol where Element : Strideable { | |
mutating func next() -> Element? { | |
guard step != 0 else { return nil } | |
defer { element = element.advanced(by: step) } |
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) | |
} |