Skip to content

Instantly share code, notes, and snippets.

@twof
Created June 30, 2020 04:09
Show Gist options
  • Save twof/97b8c1be08b8f02c30e142ecd1a64437 to your computer and use it in GitHub Desktop.
Save twof/97b8c1be08b8f02c30e142ecd1a64437 to your computer and use it in GitHub Desktop.
extension Binding: Sequence where Value == Array<Track> {
public typealias Iterator = IndexingIterator<Array<Binding<Track>>>
public __consuming func makeIterator() -> IndexingIterator<Array<Binding<Track>>> {
return IndexingIterator(_elements: (0..<wrappedValue.count).map { projectedValue[$0] })
}
}
extension Binding: Collection where Value == Array<Track> {
public typealias Element = Binding<Track>
public typealias Index = Value.Index
public var startIndex: Array<Track>.Index {
return wrappedValue.startIndex
}
public var endIndex: Array<Track>.Index {
return wrappedValue.endIndex
}
public func index(after i: Array<Track>.Index) -> Array<Track>.Index {
return wrappedValue.index(after: i)
}
public subscript(position: Array<Track>.Index) -> Binding<Track> {
return projectedValue[position]
}
}
extension Binding: BidirectionalCollection where Value == Array<Track> {
public func index(before i: Array<Track>.Index) -> Array<Track>.Index {
return wrappedValue.index(before: i)
}
}
extension Binding: RandomAccessCollection where Value == Array<Track> { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment