Created
September 23, 2018 07:58
-
-
Save jimytc/076d681b2277c56b6f4d292746b22db3 to your computer and use it in GitHub Desktop.
Compare Enumerator and Enumerator::Lazy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Regular way | |
(1..1_000_000_000).select(&:even?) | |
.map { |i| i**2 } | |
.first(10) | |
# Lazy way | |
(1..1_000_000_000).lazy | |
.select(&:even?) | |
.map { |i| i**2 } | |
.first(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment