Repository: ReactiveX/RxSwift
File: RxSwift/Observables/Zip+arity.swift (Swift)

Code before:
}

final class ZipSink2_<E1, E2, O: ObserverType> : ZipSink<O> {
    typealias R = O.E
    typealias Parent = Zip2<E1, E2, R>

    let _parent: Parent

    var _values1: Queue<E1> = Queue(capacity: 2)
    var _values2: Queue<E2> = Queue(capacity: 2)

    init(parent: Parent, observer: O, cancel: Cancelable) {
        self._parent = parent
        super.init(arity: 2, observer: observer, cancel: cancel)
    }

    override func hasElements(_ index: Int) -> Bool {
        switch index {
        case 0: return !self._values1.isEmpty
        case 1: return !self._values2.isEmpty

        default:
            rxFatalError("Unhandled case (Function)")
        }

        #if compiler(<5.0)
        return false
        #endif
    }

    func run() -> Disposable {
        let subscription1 = SingleAssignmentDisposable()
        let subscription2 = SingleAssignmentDisposable()

        let observer1 = ZipObserver(lock: self._lock, parent: self, index: 0, setNextValue: { self._values1.enqueue($0) }, this: subscription1)
        let observer2 = ZipObserver(lock: self._lock, parent: self, index: 1, setNextValue: { self._values2.enqueue($0) }, this: subscription2)

        subscription1.setDisposable(self._parent.source1.subscribe(observer1))
        subscription2.setDisposable(self._parent.source2.subscribe(observer2))

        return Disposables.create([
           subscription1,
           subscription2
        ])
    }

    override func getResult() throws -> R {
        return try self._parent._resultSelector(self._values1.dequeue()!, self._values2.dequeue()!)
    }
}


Review comment (suggestion):
`Zip+arity.swift` is generated from `Zip+arity.tt`. There is a Preprocessor in `Preprocessor/Preprocessor.xcodeproj` inside of this repo :) 

Code after:
}

final class ZipSink2_<E1, E2, O: ObserverType> : ZipSink<O> {
    typealias R = O.E
    typealias Parent = Zip2<E1, E2, R>

    let _parent: Parent

    var _values1: Queue<E1> = Queue(capacity: 2)
    var _values2: Queue<E2> = Queue(capacity: 2)

    init(parent: Parent, observer: O, cancel: Cancelable) {
        self._parent = parent
        super.init(arity: 2, observer: observer, cancel: cancel)
    }

    override func hasElements(_ index: Int) -> Bool {
        switch index {
        case 0: return !self._values1.isEmpty
        case 1: return !self._values2.isEmpty

        default:
            rxFatalError("Unhandled case (Function)")
        }

        #if !swift(>=4.2.2)
        return false
        #endif
    }

    func run() -> Disposable {
        let subscription1 = SingleAssignmentDisposable()
        let subscription2 = SingleAssignmentDisposable()

        let observer1 = ZipObserver(lock: self._lock, parent: self, index: 0, setNextValue: { self._values1.enqueue($0) }, this: subscription1)
        let observer2 = ZipObserver(lock: self._lock, parent: self, index: 1, setNextValue: { self._values2.enqueue($0) }, this: subscription2)

        subscription1.setDisposable(self._parent.source1.subscribe(observer1))
        subscription2.setDisposable(self._parent.source2.subscribe(observer2))

        return Disposables.create([
           subscription1,
           subscription2
        ])
    }

    override func getResult() throws -> R {
        return try self._parent._resultSelector(self._values1.dequeue()!, self._values2.dequeue()!)
    }
}