# Subranges of general indexes

**URL:** <https://discourse.julialang.org/t/subranges-of-general-indexes/12534>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 20, 2018, 12:48pm UTC](https://discourse.julialang.org/t/subranges-of-general-indexes/12534 "2018-07-20T12:48:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 20, 2018, 12:48pm UTC](https://discourse.julialang.org/t/subranges-of-general-indexes/12534/1 "2018-07-20T12:48:40Z")

</div>

This comes from a more general problem, but for an MWE, consider a function that returns the indices of a vector where one element is not equal to the previous one. I want it to work for general indexes, so I wrote it as

```julia
function jumpindexes(v::AbstractVector)
    xprev = first(v)
    ι = LinearIndices(v)
    j = similar(ι, 0)
    for i in ι[2:end] # PROBLEM HERE
        x = v[i]
        x == xprev || push!(j, i)
        xprev = x
    end
    j
end

```

but

```julia
julia> using OffsetArrays

julia> v = [1, 1, 2, 2, 2, 3, 3, 4]
8-element Array{Int64,1}:
 1
 1
 2
 2
 2
 3
 3
 4

julia> o = OffsetArray(v, -4:3)
OffsetArray(::Array{Int64,1}, -4:3) with eltype Int64 with indices -4:3:
 1
 1
 2
 2
 2
 3
 3
 4

julia> jumpindexes(v)
3-element Array{Int64,1}:
 3
 6
 8

julia> jumpindexes(o) # wrong, drops negative indexes
2-element Array{Int64,1}:
 2
 3

```

The problem basically boils down to

```julia
LinearIndices(o)[2:end]

```

How can I implement this algorithm with general indexing?

In general, how can I take subranges for general indexes?

(edit: on v0.7)

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 20, 2018, 7:29pm UTC](https://discourse.julialang.org/t/subranges-of-general-indexes/12534/2 "2018-07-20T19:29:05Z")

</div>

I’d use `Iterators.drop(ι, 1)` — I think that’d be just as efficient. Hopefully in 1.0 you’ll be able to use `ι[begin+1:end]`.
