Is there a way to specify a range for slicing that is bounded only on one side?I

Is there a way to specify a range for slicing that is bounded only on one side?
I can do `i = 1:10; a[i]` for bounded on both sides and I can do `i = Colon(); a[i]` for using the whole array.
Is there a simple way to do something like `i = n:end; a[i]` ?
Note that I want to reuse `i` for multiple arrays of potentially different length, so I can’t just write `i = n:lastindex(a)` .

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.

I don’t think such a thing exists - but maybe there’s a package I don’t know about. You can make your own `HalfOpenRange` type

I seem to remember a simple package doing that

Yeah, I just implemented this in my script. That works for now

``````struct LowerBoundedSlice
i::Int
end
Base.getindex(x::T, l::LowerBoundedSlice) where {T<:AbstractArray}= x[filter(>=(l.i), axes(x,1))]
``````
``````i = n:typemax(Int); a[i ∩ (begin:end)]
``````

Other solutions:

1 Like