Last active
May 22, 2016 13:36
-
-
Save mattpodwysocki/3340d29f0c42e9098718 to your computer and use it in GitHub Desktop.
Using Generators with Rx.Observable.from:
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
function* fibonacci(){ | |
var fn1 = 1; | |
var fn2 = 1; | |
while (1){ | |
var current = fn2; | |
fn2 = fn1; | |
fn1 = fn1 + current; | |
yield current; | |
} | |
} | |
Rx.Observable.from(fibonacci()) | |
.take(10) | |
.subscribe(function (x) { | |
console.log('Value: %s', x); | |
}); | |
//=> Value: 1 | |
//=> Value: 1 | |
//=> Value: 2 | |
//=> Value: 3 | |
//=> Value: 5 | |
//=> Value: 8 | |
//=> Value: 13 | |
//=> Value: 21 | |
//=> Value: 34 | |
//=> Value: 55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
checkout naman34/grunge for something similar without Rx.