# Indexin takes a collection

**URL:** <https://discourse.julialang.org/t/indexin-takes-a-collection/96315>\
**Category:** Internals & Design\
**Created:** [March 19, 2023, 7:28pm UTC](https://discourse.julialang.org/t/indexin-takes-a-collection/96315 "2023-03-19T19:28:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [March 19, 2023, 7:28pm UTC](https://discourse.julialang.org/t/indexin-takes-a-collection/96315/1 "2023-03-19T19:28:08Z")

</div>

[`indexin`](https://docs.julialang.org/en/v1/base/collections/#Base.indexin) takes a collection for both arguments, but since broadcasting is available most functions take a scalar. Why does this one take a collection for `a`?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [March 19, 2023, 7:48pm UTC](https://discourse.julialang.org/t/indexin-takes-a-collection/96315/2 "2023-03-19T19:48:57Z")

</div>

Because it can be implemented more efficiently, by only doing one pass over both `a` and `b`, resulting in `O(length(a) + length(b))` complexity instead of `O(length(a) * length(b))` complexity (at the cost of some extra allocation). See also its [implementation](https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L2376-L2406).

I guess this could be implemented specially to have broadcasting do the same kind of magic, but it’d be quite a bit more tricky (plus, I think this method has been around for quite a while).
