New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create extension functions that start addressing #103 #109
Conversation
Looks good, but please mark all methods as |
Unfortunately marking the functions as |
you could use
|
It doesn't totally eliminate the benefit since it saves a single method
call which is non-zero time spent! But yeah it's mostly useless...
…On Thu, Mar 30, 2017, 9:34 PM Stepan Goncharov ***@***.***> wrote:
you could use crossinline modifier like
= zipWith(other, BiFunction { t1, t2 -> zipper(t1, t2) })```
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#109 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEYV6eiuuHOItUdRSaXHmuxcu2ml_ks5rrFg-gaJpZM4MvGyc>
.
|
58040d1
to
6cc0863
Compare
Learnt new things about SAM adapters today! Changing to this style fixes the issue. inline fun <T, U, R> Observable<T>.withLatestFrom(other: ObservableSource<U>, crossinline combiner: (T, U) -> R): Observable<R>
= withLatestFrom(other, BiFunction<T, U, R> { t, u -> combiner.invoke(t, u) }) PR updated. |
Cool, so does this mean we can use the same signatures from a usage standpoint? Can the |
Ill take a look at this today. Sorry been quiet, trying to meet deadlines at work. |
Looking at this now. Started building an application at work and this has been driving me crazy. I will help getting all the extensions in if this approach works... |
Wow nice, that actually works. package io.reactivex.rxkotlin
import io.reactivex.Observable
import java.util.concurrent.TimeUnit
fun main(args: Array<String>) {
val source1 = Observable.interval(1, TimeUnit.SECONDS)
val source2 = Observable.interval(300, TimeUnit.MILLISECONDS)
source1.withLatestFrom(source2) { x,y -> x to y }
.subscribe(::println)
Thread.sleep(10000)
} I think I have an idea for the static factories. What if we were to create an |
The |
@chris-horner excellent, let's move forward with this then. I propose moving everything related to SAM fixes to |
@stepango where do you think we should put these development efforts? A separate branch in the main repository? Or work against Chris'? |
@thomasnield @chris-horner yeah idea sounds good, let's make a separate branch for it |
I'm liking this val newSSIMData = ObservableKt.combineLatest(newSSIMFile.toObservable(), selectedDateRange) { ssim, dates ->
SSIMRecord.forSSIMFile(ssim)
.toList().subscribeOn(Schedulers.io())
}.switchMap { it.toObservable() }
.replay(1)
.autoConnect() Having some trouble getting the object ObservableKt {
inline fun <T1,T2,R> combineLatest(source1: Observable<T1>, source2: Observable<T2>, crossinline combineFunction: (T1,T2) -> R) =
Observable.combineLatest(source1, source2,
BiFunction<T1, T2, R> { t1, t2 -> combineFunction(t1,t2) })!!
inline fun <T1,T2,T3,R> combineLatest(source1: Observable<out T1>, source2: Observable<out T2>, source3: Observable<out T3>,
crossinline combineFunction: (T1, T2, T3) -> R) =
Observable.combineLatest(source1, source2, source3, Function3<T1,T2,T3,R> { t1,t2,t3 -> combineFunction.invoke(t1,t2,t3) })!!
} |
Got it, never mind. object ObservableKt {
inline fun <T1,T2,R> combineLatest(source1: Observable<T1>, source2: Observable<T2>, crossinline combineFunction: (T1,T2) -> R) =
Observable.combineLatest(source1, source2,
BiFunction<T1, T2, R> { t1, t2 -> combineFunction(t1,t2) })!!
inline fun <T1,T2,T3,R> combineLatest(source1: Observable<T1>, source2: Observable<T2>, source3: Observable<T3>, crossinline combineFunction: (T1,T2, T3) -> R) =
Observable.combineLatest(source1, source2,source3,
io.reactivex.functions.Function3<T1, T2, T3, R> { t1: T1, t2: T2, t3: T3 -> combineFunction(t1,t2, t3) })!!
} |
I created a new branch and ported over @chris-horner's work and added some more operators. https://github.com/ReactiveX/RxKotlin/tree/sam-adapters Please help and contribute anyone who wants to get involved. I will try to add more each day until it is done. |
Closing in favor of #114 |
Making this as a first step to addressing #103.
I've only created extension functions for now, as calls like
Observable.zip()
are going to be hard to overload neatly (since Kotlin doesn't support static extension functions).