Skip to content

Instantly share code, notes, and snippets.

@dnase
Last active December 28, 2015 10:19
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 dnase/7485105 to your computer and use it in GitHub Desktop.
Save dnase/7485105 to your computer and use it in GitHub Desktop.
#define a fibonacci enumerator
fibonacci = Enumerator.new do |yielder|
a = b = 1
loop do
yielder << a
a, b = b, a + b
end
end
#curry cache to infinity
cache = (0..Float::INFINITY).lazy.map { |x| fibonacci(x) }
nth_from_list = lambda { |ary, n| ary[n] }
nth_fib = nth_from_list.curry[cache]
#list the first 100
puts fibonacci.take(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment