Skip to content

Instantly share code, notes, and snippets.

@nagachika
Created March 9, 2012 06:59
Show Gist options
  • Save nagachika/2005401 to your computer and use it in GitHub Desktop.
Save nagachika/2005401 to your computer and use it in GitHub Desktop.
example of Enumerable::Lazy#flat_map
ary = (0..10).to_a
o = Object.new
o.instance_variable_set(:@ary, ary)
def o.to_ary
@ary
end
l = [o].lazy.flat_map{|x| x}
p l.next # => 0
ary.clear
p l.next # => iteration reached an end (StopIteration)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment