Skip to content

Instantly share code, notes, and snippets.

@FFKL
Created February 3, 2020 15:38
Show Gist options
  • Save FFKL/4e7b279239fd5afc52248f75105eae05 to your computer and use it in GitHub Desktop.
Save FFKL/4e7b279239fd5afc52248f75105eae05 to your computer and use it in GitHub Desktop.
import { merge, Observable } from 'rxjs';
import { distinctUntilChanged, map, tap } from 'rxjs/operators';
export function and(a: Observable<boolean>, b: Observable<boolean>): Observable<boolean> {
let res1: boolean = false;
let res2: boolean = false;
return merge(
a.pipe(tap((res: boolean) => res1 = res)),
b.pipe(tap((res: boolean) => res2 = res))
).pipe(
map(() => res1 && res2),
distinctUntilChanged()
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment