Reverse UnitRange

My basic understanding is that 4:2 actually works and is purposefully an “empty” range. It’s just that a:b is synctactic sugar for a:1:b. You could define your own operator like (edited the snippet)

julia> …(a,b) = (a<b) ? (a:b) : (a:-1:b)
… (generic function with 1 method)

julia> 2…4
2:4

julia> 4…2
4:-1:2

I guess. And there is probably a better symbol for that…

4 Likes