//
//  PrimitiveSequence+Zip+arity.swift
//  RxSwift
//
//  Created by Krunoslav Zaher on 5/23/15.
//  Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

<% for i in 2 ... 8 { %>

// <%= i %>

extension PrimitiveSequenceType {
    /**
    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): PrimitiveSequence<TraitType, E\($0)>" }).joined(separator: ", ") %>, resultSelector: @escaping (<%= (Array(1...i).map { "E\($0)" }).joined(separator: ", ") %>) throws -> ElementType)
        -> PrimitiveSequence<TraitType, ElementType> {
            return PrimitiveSequence(raw: Observable.zip(
            <%= (Array(1...i).map { "source\($0).asObservable()" }).joined(separator: ", ") %>,
                resultSelector: resultSelector)
            )
    }
}

extension PrimitiveSequenceType where ElementType == Any {
    /**
    Merges the specified observable sequences into one observable sequence of tuples 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)

    - 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): PrimitiveSequence<TraitType, E\($0)>" }).joined(separator: ", ") %>)
        -> PrimitiveSequence<TraitType, (<%= (Array(1...i).map { "E\($0)" }).joined(separator: ", ") %>)> {
        return PrimitiveSequence(raw: Observable.zip(
                <%= (Array(1...i).map { "source\($0).asObservable()" }).joined(separator: ", ") %>)
            )
    }
}

<% } %>
