Konrad Albrecht
Konrad Albrecht

Reputation: 1919

combineLatest operator alternative

I crafted this solution as an alternative to combineLatest operator in another words want to switch my original stream into another one but still have access to value from original stream

switchMap(sourceValue => combineLatest([of(sourceValue), anotherObservable]))

Could you all help me find easier/more elegant solution than this one?

Upvotes: 0

Views: 1146

Answers (1)

Massimiliano Janes
Massimiliano Janes

Reputation: 5624

So, whenever your original observable emits a sourceValue, you want to emit pairs [sourceValue, otherValue] where otherValue comes from another observable (to be resubscribed everytime the original sourceValue changes), right ?

if so, the original code should be equivalent to the somewhat more self-explanatory (and more efficient):

switchMap(sourceValue => anotherObservable.pipe(map( otherValue => [sourceValue, otherValue] )) )

Upvotes: 2

Related Questions