Skip to content

Instantly share code, notes, and snippets.

@sullyj3
Created August 17, 2019 03:57
Show Gist options
  • Save sullyj3/b21bee802108d5036caae78ccf7e4140 to your computer and use it in GitHub Desktop.
Save sullyj3/b21bee802108d5036caae78ccf7e4140 to your computer and use it in GitHub Desktop.
class Observable<Input> {
// ... SNIP
/** Create two new observables, where one contains only those inputs for which the condition
* holds, and the other contains only those for which the condition does not hold
*/
splitBy(condition: (_:Input)=>boolean): [Observable<Input>, Observable<Input>] {
const yes = this.filter(condition);
const no = this.filter(i => ! condition(i));
return [yes, no];
}
// ... SNIP
}
function piApproximation() {
// ... SNIP
const [inside, outside] = numberPairObservable.splitBy(inCircle);
inside.subscribe( p => createDot(p, "green"), undefined);
outside.subscribe( p => createDot(p, "red"), undefined);
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment