Last active
August 29, 2015 14:18
-
-
Save JRHeaton/23529db396bf2b0f949d to your computer and use it in GitHub Desktop.
cool way to create a lazy collection that fetches from an indexed function
This file contains hidden or 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
| func lazyCollection<T>(#count: () -> Int, #get: Int -> T) -> LazyRandomAccessCollection<MapCollectionView<Range<Int>, T>> { | |
| return lazy(0..<count()).map(get) | |
| } | |
| // Example | |
| import CoreMIDI | |
| let devices = lazyCollection(count: MIDIGetNumberOfDevices, get: MIDIGetDevice) | |
| devices.array // compute all | |
| devices[0] // MIDIDeviceRef |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment