Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Simon Baslé
    @simonbasle
    1. and 2. sound sane to me, 3. I'd probably split it and put all of it into a util.rx package with as many classes as you have generic Operators, Transformers, Func and Action... but that's just me :)
    Rudi Grinberg
    @rgrinberg
    quick question, suppose I’m handling a click with an observable (i’m using rxjava but i don’t think it matters), i want a subsbcription to fire on every click and get the value of another observable in that subscription. how would i accomplish that?
    i think i need withLatestFrom
    Dorus
    @Dorus
    Sample
    David Stemmer
    @weefbellington
    withLatestFrom looks right to me, but I haven't used it much
    Dorus
    @Dorus
    The difference between sample and withLatestFrom is that sample does not combine the sequences, and does not emit duplicate values from the other subscription if it did not fire since the last click. This might or might not be what you want.
    David Stemmer
    @weefbellington
    to me, the use case that seems pretty natural for withLatestFrom is:
    1. I have a stream of button click events (an Observable<View>)
    2. I have a data stream (an Observable<Data>)
    3. every time the button is clicked, I want to emit the most recent data:clickStream.withLatestFrom(dataStream, (left, right) -> right).subscribe(parseData)
    @Dorus ^^ is that a sane thing to do...?
    Dorus
    @Dorus
    Looks right. I might name left and right click and data or even _ instead of click (.net style). I'm used to .net and the poor thing doesnt even have a withLatestFrom, so i was stuck with Sample.
    David Stemmer
    @weefbellington
    so, a Java-specific question. A class exposes a public static final Observable. Objects from other classes can subscribe to the static Observable. Is this an antipattern? It doesn't smell right to me, but I wanted a second opinion. Normally I'm very wary about memory leaks in these kinds of scenarios, and implications for unit testing.
    David Stemmer
    @weefbellington
    unrelated question:
    it seems like that if an Exception is thrown in a Subscriber's onNext method, the Observable's doOnTerminate callbacks never fire
    is there a way to get around this?
    Artem Zinnatullin :slowpoke:
    @artem-zinnatullin
    @weefbellington are you sure that you've subscribed to the Observable returned after applying doOnTerminate()?
    David Stemmer
    @weefbellington
    @artem-zinnatullin fairly certain, yes. What's happening in my case is that the source observable is emitting some data which comes from a remote API. The data returned by the API side may be malformed. If I try to do something with the malformed data in the onNext method, a RuntimeException may be thrown (NullPointerException, etc.). The behavior I'm seeing is that if a RuntimeExceptionis thrown in the subscriber onNext (or a doOnNext action), the onError callback is firing, but the doOnTerminate actions are not.
    Artem Zinnatullin :slowpoke:
    @artem-zinnatullin
    Looks like a bug, can you please post a failing test as issue to the RxJava repository? https://github.com/ReactiveX/RxJava
    David Stemmer
    @weefbellington
    @artem-zinnatullin I'll do that, thanks
    Artem Zinnatullin :slowpoke:
    @artem-zinnatullin
    :+1:
    fAns1k
    @fAns1k
    hi all, how to get data from some operation above, e.g.
    .flatMap(data -> )
                        .map(data -> mapped)
                        .compose(RxUtil.applyApiSchedulers())
                        .subscribe(nextData -> {
    //here i need to use data from flatMap
                                   },
                                throwable -> {
                                    Timber.e(throwable, "scan was fault");
                                }));
    Dorus
    @Dorus
    You need to keep the data alongside mapped.
    fAns1k
    @fAns1k
    save it outside the stream?
    Dorus
    @Dorus
    no
    fAns1k
    @fAns1k
    like create new object and push it further?
    Dorus
    @Dorus
    Simplest way would probably be a tuple or something like that, .map(data -> new tup(mapped, data)). Alternative is to use a internal stream there. I dont have the code for that at hand.
    fAns1k
    @fAns1k
    the second variant is more interesting, thanks. if you can share some code i would be appriciente
    Dorus
    @Dorus
    Do you still need mapped inside subscribe?
    fAns1k
    @fAns1k
    i need data (from snippet above) inside subscribe
    but much more interesting solution itself )
    David Stemmer
    @weefbellington
    @artem-zinnatullin: ReactiveX/RxJava#3463
    Dorus
    @Dorus
    Something like this
    .flatMap(data -> Observable.create(o -> {
            Observable.just(data)
            .map(data1 -> mapped)
            .compose(RxUtil.applyApiSchedulers())
            .map(__ -> data).subscribe(o);
        }))
    David Stemmer
    @weefbellington
    @Dorus if you have any thoughts on that issue I posted on the RxJava issue tracker I'd welcome your input as well
    Dorus
    @Dorus
    @weefbellington No clue. Looks like a bug to me indeed. Cant give you more than 'catch your own exceptions' for now
    @fAns1k Not sure if that's the cleanest way, but it should do the job.
    fAns1k
    @fAns1k
    i can’t catch where the right brackets here
    Dorus
    @Dorus
    Yeah my editor converted tabs to spaces. Should look better now.
    fAns1k
    @fAns1k
    yep, that’s more readable, thanks. will try
    Dorus
    @Dorus
    I'm not even sure if the Observable.create is needed. Might work with only Observable.just...
    fAns1k
    @fAns1k
    subscription here is also need?
    Dorus
    @Dorus
    Yes, for the Observable.create. This is without Observable.create:
        .flatMap(data -> 
            Observable.just(data)
            .map(data1 -> mapped)
            .compose(RxUtil.applyApiSchedulers())
            .map(__ -> data)
        )
    fAns1k
    @fAns1k
    is there any way to use ‘mapped’ object inside result subscription, like data and mapped object is needed
    Dorus
    @Dorus
    You can use zip where i used map(__ -> data)
    But you would still need a object that holds both data and mapped, or combine them in another meaningful way so subscribe can use it.
    fAns1k
    @fAns1k
    yep)
    Dorus
    @Dorus
    Actually no need for zip
    just .map(mapped -> combine(data, mapped)) etc.
    fAns1k
    @fAns1k
    it’s like the same as first solution - to use map -> and create result object
    Dorus
    @Dorus
    only you inject mapped in the end
    so no need to worry about it inbetween
    unpacking tuples in every map etc.
    fAns1k
    @fAns1k
    thank you very much for your help