-
-
Save laevandus/405867e0f1296ca2eda607b6e4673d31 to your computer and use it in GitHub Desktop.
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 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