Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active March 10, 2024 19:02
Show Gist options
  • Save laevandus/405867e0f1296ca2eda607b6e4673d31 to your computer and use it in GitHub Desktop.
Save laevandus/405867e0f1296ca2eda607b6e4673d31 to your computer and use it in GitHub Desktop.
struct WrappedCollection<Element>: RandomAccessCollection {
typealias Index = Int
var startIndex: Index { _startIndex() }
var endIndex: Index { _endIndex() }
subscript(position: Index) -> Element {
_position(position)
}
init<BaseCollection>(_ baseCollection: BaseCollection) where BaseCollection: RandomAccessCollection, BaseCollection.Element == Element, BaseCollection.Index == Index {
_position = { baseCollection[$0] }
_startIndex = { baseCollection.startIndex }
_endIndex = { baseCollection.endIndex }
}
private let _endIndex: () -> Index
private let _startIndex: () -> Index
private let _position: (Index) -> Element
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment