Skip to content

Instantly share code, notes, and snippets.

@flori
Created July 12, 2013 08:26
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 flori/5982798 to your computer and use it in GitHub Desktop.
Save flori/5982798 to your computer and use it in GitHub Desktop.
>> natural = (1..Float::INFINITY).lazy
# => #<Enumerator::Lazy: 1..Infinity>
>> even = natural.select { |x| x % 2 == 0 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: 1..Infinity>:select>
>> even.take(10).to_a
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment