Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Last active May 22, 2016 13:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpodwysocki/3340d29f0c42e9098718 to your computer and use it in GitHub Desktop.
Save mattpodwysocki/3340d29f0c42e9098718 to your computer and use it in GitHub Desktop.
Using Generators with Rx.Observable.from:
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
@nmn
Copy link

nmn commented Oct 4, 2014

checkout naman34/grunge for something similar without Rx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment