2

I want to evaluate two observable<boolean> and I would like to save the flow in another observable<boolean>.

I tried combineLatest(obs1$, obs2$); but it generates an observable<[boolean, boolean]>.

Is there a better function than combineLatest to evaluate both observables and returns another observable<boolean>?

user9923760
  • 596
  • 2
  • 8
  • 18

2 Answers2

5

If you want to merge the result in a single stream, use merge() from 'rxjs'. If you want to perform logical operation on both:

Combine latest accepted a project function as last parameter, for example combineLatest(obs1$, obs2$, ([first, second]) => first || second) ;

It has been deprecated. So you need to use map.

combineLatest(obs1$, obs2$,).pipe(
    map([first, second]) => first || second)
);
kvetis
  • 6,682
  • 1
  • 28
  • 48
4

I think you could use forkJoin here and you'll need to map these two observables into one value using map operator.

forkJoin([observable1, observable2]).pipe(
    map(([bool1, bool2]) => {
        return bool1 & bool2;
    })
);
Evaldas Buinauskas
  • 13,739
  • 11
  • 55
  • 107