<p dir="auto">Their is a "find" function in sorted arrays: <code class="notranslate">searchsorted</code>:<br>
</p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/JuliaLang/julia/blob/eb2a8018191adf0f5c7f64d84d7e98132d0cbdcb/base/sort.jl#L212-L229">julia/base/sort.jl</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 212 to 229
      in
      <a data-pjax="true" class="commit-tease-sha" href="/JuliaLang/julia/commit/eb2a8018191adf0f5c7f64d84d7e98132d0cbdcb">eb2a801</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L212" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="212"></td>
          <td id="LC212" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">function</span> <span class="pl-en">searchsorted</span>(v<span class="pl-k">::</span><span class="pl-c1">AbstractVector</span>, x, ilo<span class="pl-k">::</span><span class="pl-c1">T</span>, ihi<span class="pl-k">::</span><span class="pl-c1">T</span>, o<span class="pl-k">::</span><span class="pl-c1">Ordering</span>)<span class="pl-k">::</span><span class="pl-c1">UnitRange{keytype(v)}</span> <span class="pl-k">where</span> T<span class="pl-k">&lt;:</span><span class="pl-c1">Integer</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L213" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="213"></td>
          <td id="LC213" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     u <span class="pl-k">=</span> <span class="pl-c1">T</span>(<span class="pl-c1">1</span>) </td>
        </tr>

        <tr class="border-0">
          <td id="L214" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="214"></td>
          <td id="LC214" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     lo <span class="pl-k">=</span> ilo <span class="pl-k">-</span> u </td>
        </tr>

        <tr class="border-0">
          <td id="L215" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="215"></td>
          <td id="LC215" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     hi <span class="pl-k">=</span> ihi <span class="pl-k">+</span> u </td>
        </tr>

        <tr class="border-0">
          <td id="L216" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="216"></td>
          <td id="LC216" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-c1">@inbounds</span> <span class="pl-k">while</span> lo <span class="pl-k">&lt;</span> hi <span class="pl-k">-</span> u </td>
        </tr>

        <tr class="border-0">
          <td id="L217" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="217"></td>
          <td id="LC217" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">         m <span class="pl-k">=</span> <span class="pl-c1">midpoint</span>(lo, hi) </td>
        </tr>

        <tr class="border-0">
          <td id="L218" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="218"></td>
          <td id="LC218" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">         <span class="pl-k">if</span> <span class="pl-c1">lt</span>(o, v[m], x) </td>
        </tr>

        <tr class="border-0">
          <td id="L219" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="219"></td>
          <td id="LC219" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">             lo <span class="pl-k">=</span> m </td>
        </tr>

        <tr class="border-0">
          <td id="L220" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="220"></td>
          <td id="LC220" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">         <span class="pl-k">elseif</span> <span class="pl-c1">lt</span>(o, x, v[m]) </td>
        </tr>

        <tr class="border-0">
          <td id="L221" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="221"></td>
          <td id="LC221" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">             hi <span class="pl-k">=</span> m </td>
        </tr>

        <tr class="border-0">
          <td id="L222" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="222"></td>
          <td id="LC222" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">         <span class="pl-k">else</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L223" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="223"></td>
          <td id="LC223" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">             a <span class="pl-k">=</span> <span class="pl-c1">searchsortedfirst</span>(v, x, <span class="pl-c1">max</span>(lo,ilo), m, o) </td>
        </tr>

        <tr class="border-0">
          <td id="L224" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="224"></td>
          <td id="LC224" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">             b <span class="pl-k">=</span> <span class="pl-c1">searchsortedlast</span>(v, x, m, <span class="pl-c1">min</span>(hi,ihi), o) </td>
        </tr>

        <tr class="border-0">
          <td id="L225" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="225"></td>
          <td id="LC225" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">             <span class="pl-k">return</span> a <span class="pl-k">:</span> b </td>
        </tr>

        <tr class="border-0">
          <td id="L226" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="226"></td>
          <td id="LC226" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">         <span class="pl-k">end</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L227" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="227"></td>
          <td id="LC227" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">end</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L228" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="228"></td>
          <td id="LC228" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">return</span> (lo <span class="pl-k">+</span> <span class="pl-c1">1</span>) <span class="pl-k">:</span> (hi <span class="pl-k">-</span> <span class="pl-c1">1</span>) </td>
        </tr>

        <tr class="border-0">
          <td id="L229" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="229"></td>
          <td id="LC229" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">end</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">Is that a possible option to add <code class="notranslate">insorted</code> that does the same as <code class="notranslate">in</code> but knowing that the collection is sorted?</p>
<p dir="auto"><a href="https://github.com/JuliaLang/julia/pull/5379/files#r8886140">https://github.com/JuliaLang/julia/pull/5379/files#r8886140</a></p>