Created
August 17, 2019 03:57
-
-
Save sullyj3/b21bee802108d5036caae78ccf7e4140 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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