# Non-contiguous range?

Is there a way to create non-contiguous range with series notation? Like `1..3, 10..13` to produce `[1, 2, 3, 10, 11, 13]` ?

`Enum.concat(1..3, 10..13)`

8 Likes

By definition:

``````Ranges represent a sequence of zero, one or many, ascending or descending integers
with a common difference called step.
``````

So you cannot have a Range where the step varies, i.e. between 2â€¦3 is a step of 1, while 3â€¦10 is a step of 7.

If you want to make a List, then I would agree with @wojtekmach.

1 Like

And you can even make it lazy!

``````Stream.concat(1..3, 10..113)
``````
5 Likes

These are elegant! Thank you!

In both examples the â€śstepâ€ť is 1.

The â€śstepâ€ť is the difference between the current and the next element of a range.

So `1..10//2` will contain 1, 3, 5, 7, and 9.

I didnâ€™t mean to imply that those two examples are Rangesâ€¦ I just used an ellipsis between them out of habit from prose and pure math. I wanted to say that between 2 and 3 (as in `1..3`) is a step of 1, while between 3 and 10 (as in the imaginary â€śrangeâ€ť `1..3,10..13` from the original question) would have a step of 7, and therefore the definition of a Range would be violated.

Sorry for the lack of clarity in my first post.

1 Like