Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

More than 8 parameters in combineLatest using RxSwift

Is there any way to put more than 8 observable in combineLatest in RxSwift?

Here is my current implementation:

let registerUserParameters = Observable.combineLatest(
        firstname.asObservable(),
        lastname.asObservable(),
        email.asObservable(),
        mobile.asObservable(),
        addresses.asObservable(),
        cities.asObservable(),
        pword.asObservable(),
        confirm_pword.asObservable(),
        instagramid.asObservable(),
        facebookid.asObservable()) {
            ($0, $1, $2, $3, $4, $5, $6, $7, $8, $9)
    }

I found out that combineLatest only accept up to 8 parameters based on its function.

public static func combineLatest<O1, O2, O3, O4, O5, O6, O7, O8>(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4, _ source5: O5, _ source6: O6, _ source7: O7, _ source8: O8, resultSelector: @escaping (O1.E, O2.E, O3.E, O4.E, O5.E, O6.E, O7.E, O8.E) throws -> Self.E) -> RxSwift.Observable<Self.E> where O1 : ObservableType, O2 : ObservableType, O3 : ObservableType, O4 : ObservableType, O5 : ObservableType, O6 : ObservableType, O7 : ObservableType, O8 : ObservableType)
like image 204
vidalbenjoe Avatar asked Jul 17 '19 08:07

vidalbenjoe


1 Answers

You can just combine the first 8, get the combined observable, then combine the last 2, get the combined observable, then combine the two observables.

let first8 = Observable.combineLatest(
        firstname.asObservable(),
        lastname.asObservable(),
        email.asObservable(),
        mobile.asObservable(),
        addresses.asObservable(),
        cities.asObservable(),
        pword.asObservable(),
        confirm_pword.asObservable()) {
            ($0, $1, $2, $3, $4, $5, $6, $7)
    }

let last2 = Observable.combineLatest(
    instagramid.asObservable(),
    facebookid.asObservable()) {
        ($0, $1)
    }

let registerUserParameters = Observable.combineLatest(first8, last2) {
    ($0.0, $0.1, $0.2, $0.3, $0.4, $0.5, $0.6, $0.7, $1.0, $1.1)
}
like image 169
Sweeper Avatar answered Nov 15 '22 21:11

Sweeper