Skip to content

Instantly share code, notes, and snippets.

@qwtel
Created July 14, 2017 06:53
Show Gist options
  • Save qwtel/8956a5d7e995b3f41ae48a086bf2818e to your computer and use it in GitHub Desktop.
Save qwtel/8956a5d7e995b3f41ae48a086bf2818e to your computer and use it in GitHub Desktop.
function filterWithAll(p$, ...others) {
if (process.env.DEBUG && !p$) throw Error();
else if (others.length === 0) {
return this::withLatestFrom(p$)::filter(([, p]) => p)::map(([x]) => x);
} else {
return this::withLatestFrom(p$, ...others)
::filter(([, ...ps]) => ps.every(p => p))
::map(([x]) => x);
}
}
function pauseableAll(pauser$, ...others) {
if (process.env.DEBUG && !pauser$) throw Error();
if (others.length === 0) {
return pauser$::switchMap(paused => (paused ? Observable::never() : this));
} else {
return pauser$::combineLatest(...others)
::switchMap(states => (states.some(s => s) ? Observable.never() : this));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment