Skip to content

Commit 108247b

Browse files
committed
add withLatestFrom() and zipWith() variants for Pair and Triple
1 parent 6d52b65 commit 108247b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/main/kotlin/io/reactivex/rxkotlin/Flowables.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,19 @@ object Flowables {
150150
inline fun <T, U, R> Flowable<T>.withLatestFrom(other: Publisher<U>, crossinline combiner: (T, U) -> R): Flowable<R>
151151
= withLatestFrom(other, BiFunction<T, U, R> { t, u -> combiner.invoke(t, u) })
152152

153+
inline fun <T, U> Flowable<T>.withLatestFrom(other: Publisher<U>): Flowable<Pair<T, U>>
154+
= withLatestFrom(other, BiFunction{ t, u -> Pair(t,u) })
155+
156+
153157
/**
154158
* An alias to [Flowable.withLatestFrom], but allowing for cleaner lambda syntax.
155159
*/
156160
inline fun <T, T1, T2, R> Flowable<T>.withLatestFrom(o1: Publisher<T1>, o2: Publisher<T2>, crossinline combiner: (T, T1, T2) -> R): Flowable<R>
157161
= withLatestFrom(o1, o2, Function3 { t, t1, t2 -> combiner.invoke(t, t1, t2) })
158162

163+
inline fun <T, T1, T2> Flowable<T>.withLatestFrom(o1: Publisher<T1>, o2: Publisher<T2>): Publisher<Triple<T,T1,T2>>
164+
= withLatestFrom(o1, o2, Function3 { t, t1, t2 -> Triple(t, t1, t2) })
165+
159166
/**
160167
* An alias to [Flowable.withLatestFrom], but allowing for cleaner lambda syntax.
161168
*/
@@ -173,3 +180,9 @@ inline fun <T, T1, T2, T3, T4, R> Flowable<T>.withLatestFrom(o1: Publisher<T1>,
173180
*/
174181
inline fun <T, U, R> Flowable<T>.zipWith(other: Publisher<U>, crossinline zipper: (T, U) -> R): Flowable<R>
175182
= zipWith(other, BiFunction { t, u -> zipper.invoke(t, u) })
183+
184+
/**
185+
* Emits a zipped `Pair`
186+
*/
187+
inline fun <T, U> Flowable<T>.zipWith(other: Publisher<U>): Flowable<Pair<T, U>>
188+
= zipWith(other, BiFunction { t, u -> Pair(t,u) })

src/main/kotlin/io/reactivex/rxkotlin/Observables.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,21 @@ object Observables {
151151
inline fun <T, U, R> Observable<T>.withLatestFrom(other: ObservableSource<U>, crossinline combiner: (T, U) -> R): Observable<R>
152152
= withLatestFrom(other, BiFunction<T, U, R> { t, u -> combiner.invoke(t, u) })
153153

154+
/**
155+
* Emits a `Pair`
156+
*/
157+
inline fun <T, U, R> Observable<T>.withLatestFrom(other: ObservableSource<U>): Observable<Pair<T,U>>
158+
= withLatestFrom(other, BiFunction{ t, u -> Pair(t,u) })
159+
154160
/**
155161
* An alias to [Observable.withLatestFrom], but allowing for cleaner lambda syntax.
156162
*/
157163
inline fun <T, T1, T2, R> Observable<T>.withLatestFrom(o1: ObservableSource<T1>, o2: ObservableSource<T2>, crossinline combiner: (T, T1, T2) -> R): Observable<R>
158164
= withLatestFrom(o1, o2, Function3<T, T1, T2, R> { t, t1, t2 -> combiner.invoke(t, t1, t2) })
159165

166+
inline fun <T, T1, T2> Observable<T>.withLatestFrom(o1: ObservableSource<T1>, o2: ObservableSource<T2>): Observable<Triple<T,T1,T2>>
167+
= withLatestFrom(o1, o2, Function3 { t, t1, t2 -> Triple(t, t1, t2) })
168+
160169
/**
161170
* An alias to [Observable.withLatestFrom], but allowing for cleaner lambda syntax.
162171
*/
@@ -175,3 +184,8 @@ inline fun <T, T1, T2, T3, T4, R> Observable<T>.withLatestFrom(o1: ObservableSou
175184
inline fun <T, U, R> Observable<T>.zipWith(other: ObservableSource<U>, crossinline zipper: (T, U) -> R): Observable<R>
176185
= zipWith(other, BiFunction { t, u -> zipper.invoke(t, u) })
177186

187+
/**
188+
* Emits a zipped `Pair`
189+
*/
190+
inline fun <T, U> Observable<T>.zipWith(other: ObservableSource<U>): Observable<Pair<T,U>>
191+
= zipWith(other, BiFunction { t, u -> Pair(t,u) })

0 commit comments

Comments
 (0)