Is there a way to create a step in D ranges? For example, in python, range(1, 10, 2) gives me
[1, 3, 5, 7, 9]
all odds within 1 .. 10
Is there a way to do this in D using foreach?
foreach(x; 1 .. 10) {
}
I know I can use iota(start, end, step), but I also want to add an int to the very beginning and I don't know how to convert type Result to an int.
chain([2],iota(3,16,2));
chain concatenates ranges lazily
or you can go the other way around with filter!q{a==2||a&1}(iota(2,16));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With