Skip to content

Instantly share code, notes, and snippets.

@twissmueller
twissmueller / MIDIPacketList+SequenceType.swift
Created November 18, 2020 14:46 — forked from jverkoey/MIDIPacketList+SequenceType.swift
Enumerating a MIDIPacketList in Swift 2.
// Blogged at http://design.featherless.software/enumerate-midipacketlist-in-swift-part-1/
// and http://design.featherless.software/enumerate-midipacketlist-in-swift-part-2/
extension MIDIPacketList: SequenceType {
public func generate() -> AnyGenerator<MIDIPacket> {
var iterator: MIDIPacket?
var nextIndex: UInt32 = 0
return anyGenerator {
if nextIndex++ >= self.numPackets { return nil }
if iterator != nil {