Created
July 6, 2016 03:44
-
-
Save JunKikuchi/c8d41f0b89b094065d3f4ff940c92106 to your computer and use it in GitHub Desktop.
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
def lazy_fibs | |
Enumerator.new do |y| | |
a, b = 1, 1 | |
loop do | |
y << a | |
a, b = b, a + b | |
end | |
end.lazy | |
end | |
lazy_fibs.take(50).each do |n| | |
p n | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment