# OffsetArrays, inbounds, and confusion

**URL:** <https://discourse.julialang.org/t/offsetarrays-inbounds-and-confusion/81295>\
**Category:** Internals & Design\
**Tags:** indexing, arrays\
**Created:** [May 19, 2022, 3:50am UTC](https://discourse.julialang.org/t/offsetarrays-inbounds-and-confusion/81295 "2022-05-19T03:50:46Z")\
**Posts on this page:** 1\
**Showing post:** 44

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 20, 2022, 3:05am UTC](https://discourse.julialang.org/t/offsetarrays-inbounds-and-confusion/81295/44 "2022-05-20T03:05:56Z")

</div>

> pairs(collection)
> 
> Return an iterator over key =\> value pairs for any collection that maps a set of keys to a set of values. This includes arrays, where the keys are the array indices.

Also see this [old answer of mine](https://discourse.julialang.org/t/any-shortcut-to-1-length-myvector/52816/27).

To my knowledge there is no function that combines `pairs` and `enumerate`, but you can just pass the return of `pairs` to `enumerate`.

```julia
julia> using OffsetArrays
[Info: Precompiling OffsetArrays [6fe1bfb0-de20-5000-8ca7-80f57d26f881]

julia> oa = OffsetArray(["a", "b", "c", "d", "e"], -2:2)
5-element OffsetArray(::Array{String,1}, -2:2) with eltype String with indices -2:2:
 "a"
 "b"
 "c"
 "d"
 "e"

julia> for (count, (index, value)) in enumerate(pairs(oa))
           println("$count $index $value")
       end
1 -2 a
2 -1 b
3 0 c
4 1 d
5 2 e

```

---

_[View the full topic](https://discourse.julialang.org/t/offsetarrays-inbounds-and-confusion/81295)._
