Skip to content

Instantly share code, notes, and snippets.

@IlkhamGaysin
Created September 16, 2019 12:05
Show Gist options
  • Save IlkhamGaysin/92eef3f67c1b00d0a8188a3ccae13452 to your computer and use it in GitHub Desktop.
Save IlkhamGaysin/92eef3f67c1b00d0a8188a3ccae13452 to your computer and use it in GitHub Desktop.

Lazy

a = [1,2,3,4,2,5].lazy.map { |x| x * 10 }.select { |x| x > 30 } #=> no evaluation and creations of arrays

a.to_a #=> [40, 50], evaluation performed - no intermediate arrays generated.

Eager

a = [1,2,3,4,2,5].map { |x| x * 10 }.select { |x| x > 30 } #=> intermediate arrays generated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment