Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created October 3, 2014 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpodwysocki/b58ea4ceaeaa952aa389 to your computer and use it in GitHub Desktop.
Save mattpodwysocki/b58ea4ceaeaa952aa389 to your computer and use it in GitHub Desktop.
Ix is more powerful than most other combinator libraries.
function* fibonacci(){
var fn1 = 1;
var fn2 = 1;
while (1){
var current = fn2;
fn2 = fn1;
fn1 = fn1 + current;
yield current;
}
}
Ix.Enumerable.from(fibonacci())
.take(10)
.forEach(function (x, i) {
console.log('Index: %s Value: %s', i, x);
});
//=> Index: 0 Value: 1
//=> Index: 1 Value: 1
//=> Index: 2 Value: 2
//=> Index: 3 Value: 3
//=> Index: 4 Value: 5
//=> Index: 5 Value: 8
//=> Index: 6 Value: 13
//=> Index: 7 Value: 21
//=> Index: 8 Value: 34
//=> Index: 9 Value: 55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment