# Specialized Base.findfirst for ranges

**URL:** <https://discourse.julialang.org/t/specialized-base-findfirst-for-ranges/28460>\
**Category:** Performance\
**Tags:** proposal\
**Created:** [September 6, 2019, 8:34am UTC](https://discourse.julialang.org/t/specialized-base-findfirst-for-ranges/28460 "2019-09-06T08:34:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pnalysz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pnalysz/32/7306_2.png) [@pnalysz](https://discourse.julialang.org/u/pnalysz)\
**Post date:** [September 6, 2019, 8:34am UTC](https://discourse.julialang.org/t/specialized-base-findfirst-for-ranges/28460/1 "2019-09-06T08:34:00Z")

</div>

As far as I see at the moment julia uses the same findfirst method for all AbstractArray which simply iterates through all the items. Would it not make sense to have specialized method for ranges that would find the item’s index based on start/step/stop?

Thanks,  
Piotr

---

<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:** [September 6, 2019, 8:58am UTC](https://discourse.julialang.org/t/specialized-base-findfirst-for-ranges/28460/2 "2019-09-06T08:58:45Z")

</div>

There is a method for `StepRange` but not for `UnitRange`:

[https://github.com/JuliaLang/julia/blob/36c59c144122dbf09fc0e1f0f1e9defbbd2f254d/base/array.jl#L1760](https://github.com/JuliaLang/julia/blob/36c59c144122dbf09fc0e1f0f1e9defbbd2f254d/base/array.jl#L1760)

so yes, it could make sense. If someone is interested, just make a PR.

---

<div class="post-metadata">

**Author:** ![pnalysz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pnalysz/32/7306_2.png) [@pnalysz](https://discourse.julialang.org/u/pnalysz)\
**Post date:** [September 6, 2019, 9:10am UTC](https://discourse.julialang.org/t/specialized-base-findfirst-for-ranges/28460/3 "2019-09-06T09:10:08Z")

</div>

Thank you, I overlooked it. Actually StepRange is enough for me.
