All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.reactivex.rxkotlin.Observables.kt Maven / Gradle / Ivy

@file:Suppress("unused", "HasPlatformType")

package io.reactivex.rxkotlin

import io.reactivex.Observable
import io.reactivex.ObservableSource
import io.reactivex.annotations.CheckReturnValue
import io.reactivex.annotations.SchedulerSupport
import io.reactivex.functions.*

/**
 * SAM adapters to aid Kotlin lambda support
 */
object Observables {

    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  combineLatest(source1: Observable, source2: Observable, crossinline combineFunction: (T1, T2) -> R) =
            Observable.combineLatest(source1, source2,
                    BiFunction { t1, t2 -> combineFunction(t1,t2) })

    /**
     * Emits `Pair`
     */
    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    fun  combineLatest(source1: Observable, source2: Observable) =
            Observable.combineLatest(source1, source2,
                    BiFunction> { t1, t2 -> t1 to t2 })

    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  combineLatest(source1: Observable, source2: Observable, source3: Observable, crossinline combineFunction: (T1,T2, T3) -> R) =
            Observable.combineLatest(source1, source2,source3,
                    Function3 { t1: T1, t2: T2, t3: T3 -> combineFunction(t1,t2, t3) })

    /**
     * Emits `Triple`
     */
    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    fun  combineLatest(source1: Observable, source2: Observable, source3: Observable) =
            Observable.combineLatest(source1, source2, source3,
                    Function3> { t1, t2, t3 -> Triple(t1,t2,t3) })

    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  combineLatest(source1: Observable, source2: Observable, source3: Observable,
                                             source4: Observable, crossinline combineFunction: (T1,T2, T3, T4) -> R) =
            Observable.combineLatest(source1, source2,source3, source4,
                    Function4{ t1: T1, t2: T2, t3: T3, t4: T4 -> combineFunction(t1,t2, t3, t4) })


    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  combineLatest(source1: Observable, source2: Observable,
                                                source3: Observable, source4: Observable,
                                                source5: Observable, crossinline combineFunction: (T1,T2, T3, T4, T5) -> R) =
            Observable.combineLatest(source1, source2,source3, source4, source5,
                    Function5 { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5 -> combineFunction(t1,t2, t3, t4, t5) })


    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  combineLatest(source1: Observable, source2: Observable,
                                                source3: Observable, source4: Observable,
                                                source5: Observable, source6: Observable, crossinline combineFunction: (T1,T2, T3, T4, T5, T6) -> R) =
            Observable.combineLatest(source1, source2,source3, source4, source5, source6,
                    Function6 { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6 -> combineFunction(t1,t2, t3, t4, t5, t6) })

    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  combineLatest(source1: Observable, source2: Observable,
                                                   source3: Observable, source4: Observable,
                                                   source5: Observable, source6: Observable,
                                                      source7: Observable, crossinline combineFunction: (T1,T2, T3, T4, T5, T6, T7) -> R) =
            Observable.combineLatest(source1, source2,source3, source4, source5, source6, source7,
                    Function7 { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7 -> combineFunction(t1,t2, t3, t4, t5, t6, t7) })


    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  combineLatest(source1: Observable, source2: Observable,
                                                      source3: Observable, source4: Observable,
                                                      source5: Observable, source6: Observable,
                                                      source7: Observable, source8: Observable,
                                                         crossinline combineFunction: (T1,T2, T3, T4, T5, T6, T7, T8) -> R) =
            Observable.combineLatest(source1, source2,source3, source4, source5, source6, source7, source8,
                    Function8 { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8 -> combineFunction(t1,t2, t3, t4, t5, t6, t7, t8) })

    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  combineLatest(source1: Observable, source2: Observable,
                                                         source3: Observable, source4: Observable,
                                                         source5: Observable, source6: Observable,
                                                         source7: Observable, source8: Observable,
                                                         source9: Observable, crossinline combineFunction: (T1,T2, T3, T4, T5, T6, T7, T8, T9) -> R) =
            Observable.combineLatest(source1, source2,source3, source4, source5, source6, source7, source8, source9,
                    Function9 { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9 -> combineFunction(t1,t2, t3, t4, t5, t6, t7, t8, t9) })


    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  zip(source1: Observable, source2: Observable, crossinline combineFunction: (T1, T2) -> R) =
            Observable.zip(source1, source2,
                    BiFunction { t1, t2 -> combineFunction(t1,t2) })


    /**
     * Emits `Pair`
     */
    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    fun  zip(source1: Observable, source2: Observable) =
            Observable.zip(source1, source2,
                    BiFunction> { t1, t2 -> t1 to t2 })

    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  zip(source1: Observable, source2: Observable, source3: Observable, crossinline combineFunction: (T1,T2, T3) -> R) =
            Observable.zip(source1, source2,source3,
                    Function3 { t1: T1, t2: T2, t3: T3 -> combineFunction(t1,t2, t3) })

    /**
     * Emits `Triple`
     */
    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    fun  zip(source1: Observable, source2: Observable, source3: Observable) =
            Observable.zip(source1, source2, source3,
                    Function3> { t1, t2, t3 -> Triple(t1,t2,t3) })

    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  zip(source1: Observable, source2: Observable, source3: Observable, source4: Observable, crossinline combineFunction: (T1,T2, T3, T4) -> R) =
            Observable.zip(source1, source2,source3, source4,
                    Function4 { t1: T1, t2: T2, t3: T3, t4: T4 -> combineFunction(t1,t2, t3, t4) })

    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  zip(source1: Observable, source2: Observable,
                                      source3: Observable, source4: Observable,
                                      source5: Observable, crossinline combineFunction: (T1,T2, T3, T4, T5) -> R) =
            Observable.zip(source1, source2,source3, source4, source5,
                    Function5 { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5 -> combineFunction(t1,t2, t3, t4, t5) })



    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  zip(source1: Observable, source2: Observable,
                                                   source3: Observable, source4: Observable,
                                                   source5: Observable, source6: Observable, crossinline combineFunction: (T1,T2, T3, T4, T5, T6) -> R) =
            Observable.zip(source1, source2,source3, source4, source5, source6,
                    Function6 { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6 -> combineFunction(t1,t2, t3, t4, t5, t6) })

    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  zip(source1: Observable, source2: Observable,
                                                      source3: Observable, source4: Observable,
                                                      source5: Observable, source6: Observable,
                                                      source7: Observable, crossinline combineFunction: (T1,T2, T3, T4, T5, T6, T7) -> R) =
            Observable.zip(source1, source2,source3, source4, source5, source6, source7,
                    Function7 { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7 -> combineFunction(t1,t2, t3, t4, t5, t6, t7) })


    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  zip(source1: Observable, source2: Observable,
                                                         source3: Observable, source4: Observable,
                                                         source5: Observable, source6: Observable,
                                                         source7: Observable, source8: Observable,
                                                         crossinline combineFunction: (T1,T2, T3, T4, T5, T6, T7, T8) -> R) =
            Observable.zip(source1, source2,source3, source4, source5, source6, source7, source8,
                    Function8 { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8 -> combineFunction(t1,t2, t3, t4, t5, t6, t7, t8) })

    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    inline fun  zip(source1: Observable, source2: Observable,
                                                            source3: Observable, source4: Observable,
                                                            source5: Observable, source6: Observable,
                                                            source7: Observable, source8: Observable,
                                                            source9: Observable, crossinline combineFunction: (T1,T2, T3, T4, T5, T6, T7, T8, T9) -> R) =
            Observable.zip(source1, source2,source3, source4, source5, source6, source7, source8, source9,
                    Function9 { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9 -> combineFunction(t1,t2, t3, t4, t5, t6, t7, t8, t9) })

}


/**
 * An alias to [Observable.withLatestFrom], but allowing for cleaner lambda syntax.
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
inline fun  Observable.withLatestFrom(other: ObservableSource, crossinline combiner: (T, U) -> R): Observable
        = withLatestFrom(other, BiFunction { t, u -> combiner.invoke(t, u) })

/**
 * Emits a `Pair`
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
fun  Observable.withLatestFrom(other: ObservableSource): Observable>
        = withLatestFrom(other, BiFunction{ t, u -> Pair(t,u) })

/**
 * An alias to [Observable.withLatestFrom], but allowing for cleaner lambda syntax.
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
inline fun  Observable.withLatestFrom(o1: ObservableSource, o2: ObservableSource, crossinline combiner: (T, T1, T2) -> R): Observable
        = withLatestFrom(o1, o2, Function3 { t, t1, t2 -> combiner.invoke(t, t1, t2) })

@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
fun  Observable.withLatestFrom(o1: ObservableSource, o2: ObservableSource): Observable>
        = withLatestFrom(o1, o2, Function3 { t, t1, t2 -> Triple(t, t1, t2) })

/**
 * An alias to [Observable.withLatestFrom], but allowing for cleaner lambda syntax.
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
inline fun  Observable.withLatestFrom(o1: ObservableSource, o2: ObservableSource, o3: ObservableSource, crossinline combiner: (T, T1, T2, T3) -> R): Observable
        = withLatestFrom(o1, o2, o3, Function4 { t, t1, t2, t3 -> combiner.invoke(t, t1, t2, t3) })

/**
 * An alias to [Observable.withLatestFrom], but allowing for cleaner lambda syntax.
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
inline fun  Observable.withLatestFrom(o1: ObservableSource, o2: ObservableSource, o3: ObservableSource, o4: ObservableSource, crossinline combiner: (T, T1, T2, T3, T4) -> R): Observable
        = withLatestFrom(o1, o2, o3, o4, Function5 { t, t1, t2, t3, t4 -> combiner.invoke(t, t1, t2, t3, t4) })

/**
 * An alias to [Observable.zipWith], but allowing for cleaner lambda syntax.
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
inline fun  Observable.zipWith(other: ObservableSource, crossinline zipper: (T, U) -> R): Observable
        = zipWith(other, BiFunction { t, u -> zipper.invoke(t, u) })

/**
 * Emits a zipped `Pair`
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
fun  Observable.zipWith(other: ObservableSource): Observable>
        = zipWith(other, BiFunction { t, u -> Pair(t,u) })