# Error: findfirst(((x,y))-\>x==1, \[(1,2), (3,4)\])

**URL:** https://discourse.julialang.org/t/error-findfirst-x-y-x-1-1-2-3-4/78733
**Category:** General Usage
**Created:** [March 30, 2022, 11:33am UTC](https://discourse.julialang.org/t/error-findfirst-x-y-x-1-1-2-3-4/78733 "2022-03-30T11:33:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)
#### Post date: [March 30, 2022, 11:33am UTC](https://discourse.julialang.org/t/error-findfirst-x-y-x-1-1-2-3-4/78733/1 "2022-03-30T11:33:30Z")

</div>

Why does this fail? 🤔

```julia
julia> findfirst(((x,y))->x==1, [(1,2), (3,4)])

ERROR: MethodError: no method matching (::var"#7#8")(::Tuple{Int64, 
Int64})

```

while these two are fine:

```julia
julia> findfirst([(1,2), (3,4)]) do (x, y)
           x==1
       end
1

```

```julia
function cond((x, y))
       x==1
end

julia> findfirst(cond, [(1,2), (3,4)])
1

```

---

<div class="post-metadata">

### Author: ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)
#### Post date: [March 30, 2022, 11:40am UTC](https://discourse.julialang.org/t/error-findfirst-x-y-x-1-1-2-3-4/78733/2 "2022-03-30T11:40:29Z")

</div>

I think this is since the double parenthesis does not really do much here, so you actually get a function expecting two variables.

What you can do is add an extra comma to show it is supposed to be a tuple of a single argument (that is itself a tuple)

```julia
findfirst(((x,y),) -> x == 1, [(1, 2), (3, 4)])

```

---

<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 30, 2022, 11:42am UTC](https://discourse.julialang.org/t/error-findfirst-x-y-x-1-1-2-3-4/78733/3 "2022-03-30T11:42:24Z")

</div>

Note that this is the same problem as:

```julia
julia> f = ((x,y)) -> x == 1
#20 (generic function with 1 method)

julia> f((1,1))
ERROR: MethodError: no method matching (::var"#20#21")(::Tuple{Int64, Int64})
Closest candidates are:
  (::var"#20#21")(::Any, ::Any) at REPL[17]:1
Stacktrace:
 [1] top-level scope
   @ REPL[18]:1

julia> f(1,1)
true

```

seems to be a parsing edge case.

You can solve that by adding a comma:

```julia
julia> findfirst( ((x,y),) -> x == 1 , [(1,2), (3,4)])
1

```

---

<div class="post-metadata">

### Author: ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)
#### Post date: [March 30, 2022, 11:55am UTC](https://discourse.julialang.org/t/error-findfirst-x-y-x-1-1-2-3-4/78733/4 "2022-03-30T11:55:30Z")

</div>

Thank you for the tip! Yes it seems like an edge case.
