Created
February 3, 2020 15:38
-
-
Save FFKL/4e7b279239fd5afc52248f75105eae05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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