Skip to content

Instantly share code, notes, and snippets.

@BFalkner
Created June 16, 2010 17:53
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 BFalkner/441028 to your computer and use it in GitHub Desktop.
Save BFalkner/441028 to your computer and use it in GitHub Desktop.
> LazyEnumerator.new([1, 2, 3]).
map{|el| puts "add #{el}"; el + 1}.
map{|el| puts "mul #{el}"; el * 2}.
each{|el| puts el}
add 1
mul 2
4
add 2
mul 3
6
add 3
mul 4
8
=> #<FunTree::LazyEnumerator:0x100377520 @transformation=#<Proc:0x0000000100119cb0@./lazy_enumerator.rb:15>, @enumerable=#<FunTree::LazyEnumerator:0x100377778 @transformation=#<Proc:0x0000000100119cb0@./lazy_enumerator.rb:15>, @enumerable=#<FunTree::LazyEnumerator:0x100377b88 @transformation=#<Proc:0x000000010011d770@./lazy_enumerator.rb:6>, @enumerable=[1, 2, 3]>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment