Skip to content

SwitchMap guaranteeing atleast 1 emission #6306

@ursusursus

Description

@ursusursus

Hi, I have trouble figuring this one out, I even check the extensions library.

My usecase is I have upstream of states which I switchMap into contacts observable. Turns out I need my downstream to always see all states (after the switchmapped observable), i.e. all of upstream, where they might get omitted via switchMap.

concatMap doesnt seem to work, because the contactsObservable never completes.

val statesObservable = Observable.just(A, B, C, D)
statesObservable
   .switchMap { state -> contactsObservable
                                        .map { contact -> pairOf(state, contact}
   }
   .subsrcibe { 
     // Needs to see every state emitted, for example (A, Contact1), (A, Contact2), B(Contact1), C(Contact1), D(Contact2)
   }

Is there a way I can guarantee alteast 1 emission of mapped observable with switchMap? I.e. queue upstream states until atleast 1 contact emit per state.

Or, contactMap takeUntil new upstream value?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions