3 ms·
I don't know how common working with ranges is in Zig. Ruby would iterate on multiple ranges by converting them to arrays one = (1..3) seven = (7..10) (o
by pmontra 4y ago
I don't know how common working with ranges is in Zig.
Ruby would iterate on multiple ranges by converting them to arrays
one = (1..3)
seven = (7..10)
(one.to_a + seven.to_a).each {|n| puts n}
I suppose that if it was common they would have added a + method to Range.
Actually I think that's possible to implement it with a refinement on the Range class.
Yup, it works. First time I ever used refinements.
module JoinRanges
refine Range do
def +(other)
self.to_a + other.to_a
end
end
end
using JoinRanges
one = (1..3)
seven = (7..10)
(one + seven).each {|n| puts n}
- kdmccormick 4y agoThis is different. You are concatenating the arrays, whereas the article & discussion are about zipping arrays.