Created
October 3, 2014 23:58
-
-
Save mattpodwysocki/b58ea4ceaeaa952aa389 to your computer and use it in GitHub Desktop.
Ix is more powerful than most other combinator libraries.
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; | |
} | |
} | |
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