# \`indexin\` should accept Tuples as second argument?

**URL:** https://discourse.julialang.org/t/indexin-should-accept-tuples-as-second-argument/57211
**Category:** Internals & Design
**Created:** [March 15, 2021, 4:34pm UTC](https://discourse.julialang.org/t/indexin-should-accept-tuples-as-second-argument/57211 "2021-03-15T16:34:11Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [March 15, 2021, 4:34pm UTC](https://discourse.julialang.org/t/indexin-should-accept-tuples-as-second-argument/57211/1 "2021-03-15T16:34:11Z")

</div>

As a side note from [this thread](https://discourse.julialang.org/t/type-instability-in-performance-critical-function/57195/17), I noticed that the implementation of `indexin`, which is:

```julia
function indexin(a, b::AbstractArray)
    inds = keys(b)
    bdict = Dict{eltype(b),eltype(inds)}()
    for (val, ind) in zip(b, inds)
        get!(bdict, val, ind)
    end
    return Union{eltype(inds), Nothing}[
        get(bdict, i, nothing) for i in a
    ]
end

```

can be adapted to accept `Tuples` as the second argument simply by removing the type annotation. I mean, this works:

```julia
julia> x = rand(1:10,10); y = ntuple(i->rand(1:10),20);

julia> indexin(x,y)
ERROR: MethodError: no method matching indexin(::Array{Int64,1}, ::NTuple{20,Int64})
Closest candidates are:
  indexin(::Any, ::AbstractArray) at array.jl:2333
Stacktrace:
 [1] top-level scope at REPL[81]:1

# removing the requirement of `b` being an AbstractArray
julia> indexin_new(x,y) 
10-element Array{Union{Nothing, Int64},1}:
  3
 17
  1
  1
 15
  3
   nothing
  8
  2
 17

```

It seems to work well and perform ok.

Is there any other reason for not accepting Tuples there, or that constraint could be alleviated?

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [March 15, 2021, 4:40pm UTC](https://discourse.julialang.org/t/indexin-should-accept-tuples-as-second-argument/57211/2 "2021-03-15T16:40:57Z")

</div>

> [@lmiq](#):
>
> `inds = keys(b)`

Tangentially, I noticed this:

```julia
julia> keys([1,2,3])
3-element LinearIndices{1, Tuple{Base.OneTo{Int64}}}:
 1
 2
 3

julia> keys((1,2,3))
Base.OneTo(3)

```

Since `keys` of multidimensional array would return `CartesianIndices`, I wonder what’s the purpose of wrapping `OneTo` with `LinearIndices` for vector
