These are chat archives for ReactiveX/RxJava

13th
Sep 2018
Sergey Serdyuk
@neee
Sep 13 2018 08:11
Hi everyone, I have a question:
ServiceReturnObservable1.getData()
.flatMap(r -> serviceReturnObservable2.getSomeData(r.getValue()))
.flatMap( here I want to work with ServiceReturnObservable1.getData() and serviceReturnObservable2.getSomeData(r.getValue()))
Pulkit Kumar
@pulkitkumar
Sep 13 2018 09:22
@neee serviceReturnObservable2.getSomeData(r.getValue()) should emit an object which has everything you need to chain it further. Since it is already accepting value emitted by ServiceReturnObservable1, you should be able to add those values to the object emitted by ServiceReturnObservable2 .
Dan O'Reilly
@dano
Sep 13 2018 14:19
@neee i usually .map to a tuple type inside of the first flatMap call, or nest the second flatMap call inside the first
i have a bunch of helpers for automatically "chaining" the second emitted value into a tuple with the previous emitted value, and then unpacking the tuple in the next call
So you'd end up with
ServiceReturnObservable1.getData()
    .flatMap(chainObs(r -> serviceReturnObservable2.getSomeData(r.getValue())))
    .flatMap(unpack((r1, r2) -> ...))
Ignacio Baca Moreno-Torres
@ibaca
Sep 13 2018 14:32
you know this sorcery works since java8 and can be saved in var since java10 :scream:
Observable.just(1,2,3,4)
        .flatMap(n -> Observable.just("a","b","c")
                .map(s -> new Object() { Integer num = n; String str = s; }))
        .subscribe(obj -> System.out.println(obj.num + ":" + obj.str));
Ricky Limka
@rcklmk_twitter
Sep 13 2018 15:49

Hey everyone, today I encountered a strange behavior with Observable.create:

...
private ObservableEmitter<Action> extEmitter;

    public Test() {
        Observable<Action> actions = Observable.create(emitter -> {
            extEmitter = emitter;

            emitter.onNext(Action.TEST);
            emitter.onNext(Action.REVERT);
            emitter.onNext(Action.TEST);
            emitter.onNext(Action.REVERT);
        });


        Observable<Action> reverts = actions.filter(Action.REVERT::equals);
        Observable<Action> tests = actions.filter(Action.TEST::equals);

        Observable.merge(tests, reverts).subscribe(System.out::println);

        extEmitter.onNext(Action.TEST);
        extEmitter.onNext(Action.REVERT);
        extEmitter.onNext(Action.TEST);
        extEmitter.onNext(Action.REVERT);
    }
...

Does anyone know why using extEmitter (emitter outside of lambda) emits different results than emitter inside lambda?

↑ what is the common practice for exporting emitter outside for pushing custom values from other java classes?
Ricky Limka
@rcklmk_twitter
Sep 13 2018 16:02
I should have used Rx.Subject instead?