Skip to content

Instantly share code, notes, and snippets.

@sashadev-sky
Last active May 20, 2020 19:14
Show Gist options
  • Select an option

  • Save sashadev-sky/6b624d37488b96cd57a45408eda1ef6c to your computer and use it in GitHub Desktop.

Select an option

Save sashadev-sky/6b624d37488b96cd57a45408eda1ef6c to your computer and use it in GitHub Desktop.
use Enumerable#lazy method: avoid endless loop and get just the values u need
range = 1..Float::INFINITY
p range.lazy.collect { |x| x * x }.first(10)
#=> [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment