Last active
July 5, 2018 18:47
-
-
Save jaydorsey/cbbb9dcc13760b9d9f367899d9158e60 to your computer and use it in GitHub Desktop.
Fibonacci enumerator
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
fib = -> { Enumerator.new { |y| a = b = 1; loop { y << a; a, b = b, a + b } } } | |
puts fib.call.take(20) | |
x = fib.call | |
x.next => 1 | |
x.next => 1 | |
x.next => 2 | |
... | |
x.next => 13 | |
x.next => 21 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment