RxJava: wait another observable result

VB_

How to wait another observable result while transforming the current one?

I have a list of user ids (userIdsList), and I should convert them to a map. In map key is represented by userId and value is boolean, which indicates if userId containsin regUsers.

return Observable
   .<List<Long>>from(userIdsList)
   .groupBy(id -> id, id -> regUsers.contains(id)); //PROBLEM: regUsers is Observable<List<Long>>
m.ostroverkhov

Somewhat convoluted solution.

      List<Long> ids = Arrays.asList(1L, 2L, 3L);
      Observable<List<Long>> regUsers = Observable.just(Arrays.asList(1L, 2L)).cache();

      Observable<Long> idsStream = Observable.from(ids).cache();
      Observable<Boolean> containsStream = idsStream
             .concatMap(id -> regUsers.map(regList -> regList.contains(id)));

      idsStream.zipWith(containsStream, (Func2<Long, Boolean, Pair>) Pair::new)
            .toMap(Pair::getLeft, Pair::getRight).subscribe(System.out::println);


  private static class Pair<K, V> {

    private final K left;
    private final V right;

    public Pair(K left, V right) {
        this.left = left;
        this.right = right;
    }

    public K getLeft() {
        return left;
    }

    public V getRight() {
        return right;
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

rxjava collect objects by condition and wait for another observable

RXJS Emit first result and then wait for another observable

Wait observable inside another observable

How to wrap observable inside another observable in RxJava?

RxJS wait for observable then create another observable, and so on

RXAndroid: Observable wait for another observable complete

How to subscribe (or not!) to an observable depending of the result of another observable

RxJava - Control one Observable by another one

RxJava + Kotlin - Using one observable in the creation of another

how to wait for an observable but return the previous observable result in rxjs?

RxJava: Combining hot and cold observable to wait for each other

RxJava - how to wait to result of async tasks wihiting doOnNext

Wait for another method to invoke and then continue with result

RxJava get result of previous observable in chained network request

Bind RxSwift observable result to another observables

Angular: wait for Observable inside a function before returning result

How to call Observable from suspend method and wait for result

How to conditionally subscribe inside an observable, wait for response and return the complete result?

Use data from one observable in another and then return result as other observable

Angular - How to use the result of an observable, inside another observable?

Mapping an Observable in array items of another Observable, flattening the result

Giving an RxJava Observable something to emit from another method

Zip list of observables into another Zip observable RxJava2

RxJava: Unsubscribe async observable from within another async production

How to make one Observable sequence wait for another to complete before emitting?

Wait for several rxjs observable inside foreach till finished to execute an another

In an unit test, how to wait for an RxJava2 Observable to finish before asserting results

RxJava: prevent an observable from emitting until data from another observable is emitted

How to Make an Observable that Emits Combined Items Emitted by Another Observable in RxJava 2?