|
| 1 | +package io.reactivex.rxkotlin |
| 2 | + |
| 3 | +import io.reactivex.Flowable |
| 4 | +import io.reactivex.functions.BiFunction |
| 5 | +import io.reactivex.functions.Function3 |
| 6 | +import io.reactivex.functions.Function4 |
| 7 | +import io.reactivex.functions.Function5 |
| 8 | +import org.reactivestreams.Publisher |
| 9 | + |
| 10 | + |
| 11 | +object FlowableKt { |
| 12 | + |
| 13 | + inline fun <T1,T2,R> combineLatest(source1: Flowable<T1>, source2: Flowable<T2>, crossinline combineFunction: (T1, T2) -> R) = |
| 14 | + Flowable.combineLatest(source1, source2, |
| 15 | + BiFunction<T1, T2, R> { t1, t2 -> combineFunction(t1,t2) })!! |
| 16 | + |
| 17 | + inline fun <T1,T2,T3,R> combineLatest(source1: Flowable<T1>, source2: Flowable<T2>, source3: Flowable<T3>, crossinline combineFunction: (T1, T2, T3) -> R) = |
| 18 | + Flowable.combineLatest(source1, source2,source3, |
| 19 | + io.reactivex.functions.Function3<T1, T2, T3, R> { t1: T1, t2: T2, t3: T3 -> combineFunction(t1,t2, t3) })!! |
| 20 | + |
| 21 | + inline fun <T1,T2,T3,T4,R> combineLatest(source1: Flowable<T1>, source2: Flowable<T2>, source3: Flowable<T3>, |
| 22 | + source4: Flowable<T4>, crossinline combineFunction: (T1, T2, T3, T4) -> R) = |
| 23 | + Flowable.combineLatest(source1, source2,source3, source4, |
| 24 | + io.reactivex.functions.Function4<T1, T2, T3, T4, R> { t1: T1, t2: T2, t3: T3, t4: T4 -> combineFunction(t1,t2, t3, t4) })!! |
| 25 | + |
| 26 | + |
| 27 | + inline fun <T1,T2,T3,T4,T5,R> combineLatest(source1: Flowable<T1>, source2: Flowable<T2>, |
| 28 | + source3: Flowable<T3>, source4: Flowable<T4>, |
| 29 | + source5: Flowable<T5>, crossinline combineFunction: (T1, T2, T3, T4, T5) -> R) = |
| 30 | + Flowable.combineLatest(source1, source2,source3, source4, source5, |
| 31 | + io.reactivex.functions.Function5<T1, T2, T3, T4, T5, R> { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5 -> combineFunction(t1,t2, t3, t4, t5) })!! |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + inline fun <T1,T2,R> zip(source1: Flowable<T1>, source2: Flowable<T2>, crossinline combineFunction: (T1, T2) -> R) = |
| 38 | + Flowable.zip(source1, source2, |
| 39 | + BiFunction<T1, T2, R> { t1, t2 -> combineFunction(t1,t2) })!! |
| 40 | + |
| 41 | + inline fun <T1,T2,T3,R> zip(source1: Flowable<T1>, source2: Flowable<T2>, source3: Flowable<T3>, crossinline combineFunction: (T1, T2, T3) -> R) = |
| 42 | + Flowable.zip(source1, source2,source3, |
| 43 | + io.reactivex.functions.Function3<T1, T2, T3, R> { t1: T1, t2: T2, t3: T3 -> combineFunction(t1,t2, t3) })!! |
| 44 | + |
| 45 | + inline fun <T1,T2,T3,T4,R> zip(source1: Flowable<T1>, source2: Flowable<T2>, source3: Flowable<T3>, source4: Flowable<T4>, crossinline combineFunction: (T1, T2, T3, T4) -> R) = |
| 46 | + Flowable.zip(source1, source2,source3, source4, |
| 47 | + io.reactivex.functions.Function4<T1, T2, T3, T4, R> { t1: T1, t2: T2, t3: T3, t4: T4 -> combineFunction(t1,t2, t3, t4) })!! |
| 48 | + |
| 49 | + inline fun <T1,T2,T3,T4,T5,R> zip(source1: Flowable<T1>, source2: Flowable<T2>, |
| 50 | + source3: Flowable<T3>, source4: Flowable<T4>, |
| 51 | + source5: Flowable<T5>, crossinline combineFunction: (T1, T2, T3, T4, T5) -> R) = |
| 52 | + Flowable.zip(source1, source2,source3, source4, source5, |
| 53 | + io.reactivex.functions.Function5<T1, T2, T3, T4, T5, R> { t1: T1, t2: T2, t3: T3, t4: T4, t5: T5 -> combineFunction(t1,t2, t3, t4, t5) })!! |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +/** |
| 58 | + * An alias to [Flowable.withLatestFrom], but allowing for cleaner lambda syntax. |
| 59 | + */ |
| 60 | +inline fun <T, U, R> Flowable<T>.withLatestFrom(other: Publisher<U>, crossinline combiner: (T, U) -> R): Flowable<R> |
| 61 | + = withLatestFrom(other, BiFunction<T, U, R> { t, u -> combiner.invoke(t, u) }) |
| 62 | + |
| 63 | +/** |
| 64 | + * An alias to [Flowable.withLatestFrom], but allowing for cleaner lambda syntax. |
| 65 | + */ |
| 66 | +inline fun <T, T1, T2, R> Flowable<T>.withLatestFrom(o1: Publisher<T1>, o2: Publisher<T2>, crossinline combiner: (T, T1, T2) -> R): Flowable<R> |
| 67 | + = withLatestFrom(o1, o2, Function3<T, T1, T2, R> { t, t1, t2 -> combiner.invoke(t, t1, t2) }) |
| 68 | + |
| 69 | +/** |
| 70 | + * An alias to [Flowable.withLatestFrom], but allowing for cleaner lambda syntax. |
| 71 | + */ |
| 72 | +inline fun <T, T1, T2, T3, R> Flowable<T>.withLatestFrom(o1: Publisher<T1>, o2: Publisher<T2>, o3: Publisher<T3>, crossinline combiner: (T, T1, T2, T3) -> R): Flowable<R> |
| 73 | + = withLatestFrom(o1, o2, o3, Function4<T, T1, T2, T3, R> { t, t1, t2, t3 -> combiner.invoke(t, t1, t2, t3) }) |
| 74 | + |
| 75 | +/** |
| 76 | + * An alias to [Flowable.withLatestFrom], but allowing for cleaner lambda syntax. |
| 77 | + */ |
| 78 | +inline fun <T, T1, T2, T3, T4, R> Flowable<T>.withLatestFrom(o1: Publisher<T1>, o2: Publisher<T2>, o3: Publisher<T3>, o4: Publisher<T4>, crossinline combiner: (T, T1, T2, T3, T4) -> R): Flowable<R> |
| 79 | + = withLatestFrom(o1, o2, o3, o4, Function5<T, T1, T2, T3, T4, R> { t, t1, t2, t3, t4 -> combiner.invoke(t, t1, t2, t3, t4) }) |
| 80 | + |
| 81 | +/** |
| 82 | + * An alias to [Flowable.zipWith], but allowing for cleaner lambda syntax. |
| 83 | + */ |
| 84 | +inline fun <T, U, R> Flowable<T>.zipWith(other: Publisher<U>, crossinline zipper: (T, U) -> R): Flowable<R> |
| 85 | + = zipWith(other, BiFunction { t, u -> zipper.invoke(t, u) }) |
0 commit comments