3

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.

Phil Kurtis
  • 189
  • 1
  • 1
  • 9

1 Answers1

6

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));

ratchet freak
  • 47,288
  • 5
  • 68
  • 106