//
//  Infallible+Zip+arity.swift
//  RxSwift
//
//  Created by Shai Mishali on 27/8/20.
//  Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

// MARK: - Zip

<% for i in 2 ... 8 { %>
// <%= i %>
extension InfallibleType {
    /**
    Merges the specified observable sequences into one observable sequence by using the selector function whenever all of the observable sequences have produced an element at a corresponding index.

    - seealso: [zip operator on reactivex.io](http://reactivex.io/documentation/operators/zip.html)

    - parameter resultSelector: Function to invoke for each series of elements at corresponding indexes in the sources.
    - returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
    */
    public static func zip<<%= (Array(1...i).map { "E\($0)" }).joined(separator: ", ") %>>(<%= (Array(1...i).map { "_ source\($0): Infallible<E\($0)>" }).joined(separator: ", ") %>, resultSelector: @escaping (<%= (Array(1...i).map { "E\($0)" }).joined(separator: ", ") %>) throws -> Element)
        -> Infallible<Element> {
        Infallible(
            Observable.zip(<%= (Array(1...i).map { "source\($0).asObservable()" }).joined(separator: ", ") %>, resultSelector: resultSelector)
        )
    }
}
<% } %>
