Created
August 4, 2023 15:44
-
-
Save nsmmrs/f67b5e9e0c48a45bc3d0656d85fc5bb0 to your computer and use it in GitHub Desktop.
Ruby Lazy Enumerator Demo
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
def lazy_demo(n, group_size:n, groups:n) | |
(1..Float::INFINITY) | |
.lazy | |
.map{|x| x * n } | |
.select{|product| product.even? } | |
.each_slice(group_size) | |
.map{|group| group.map(&:to_s).join(",") } | |
.first(groups) | |
end |
Author
nsmmrs
commented
Aug 4, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment