# Anonymous functions with tuple arguments

**URL:** <https://discourse.julialang.org/t/anonymous-functions-with-tuple-arguments/3306>\
**Category:** General Usage\
**Created:** [April 20, 2017, 11:24pm UTC](https://discourse.julialang.org/t/anonymous-functions-with-tuple-arguments/3306 "2017-04-20T23:24:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [April 20, 2017, 11:24pm UTC](https://discourse.julialang.org/t/anonymous-functions-with-tuple-arguments/3306/1 "2017-04-20T23:24:55Z")

</div>

I have a feeling this is a stupid question, but here it is anyway:

Suppose I have a collection of tuples.  
Would it be possible to write anonymous function (x,y,…)-\>… where arguments are the tuple elements?

An example:

```julia
A = [(x,y) for x=1:5, y=1:5]

```

I can extract and use the tuple elements directly in for loop:

```julia
for (x,y) in A
    println(x,y)
end

```

For an anonymous function I can write something like:

```julia
filter(t -> t[1]==1 || t[2]==1, A)

```

but I feel I want to write this as:

```julia
filter((x,y) -> x==1 || y==1, A)

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [April 21, 2017, 2:29am UTC](https://discourse.julialang.org/t/anonymous-functions-with-tuple-arguments/3306/2 "2017-04-21T02:29:27Z")

</div>

I don’t think that’s currently possible, but it’s been discussed: [https://github.com/JuliaLang/julia/issues/6614](https://github.com/JuliaLang/julia/issues/6614)

One other option would be:

```julia
filter(A) do xy
  x, y = xy
  x == 1 || y == 1
end

```

---

<div class="post-metadata">

**Author:** ![Robert\_Honig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robert_honig/32/4930_2.png) [@Robert\_Honig](https://discourse.julialang.org/u/Robert_Honig)\
**Post date:** [May 11, 2020, 9:36pm UTC](https://discourse.julialang.org/t/anonymous-functions-with-tuple-arguments/3306/3 "2020-05-11T21:36:20Z")

</div>

> [@greg\_plowman](#):
>
> ```julia
> filter((x,y) -> x==1 || y==1, A)
> 
> ```

Note that this is now possible to do as follows:

```julia
filter(((x,y),) -> x==1 || y==1, A)

```
