# Why I cannot use a tuple in \`map\` directly?

**URL:** <https://discourse.julialang.org/t/why-i-cannot-use-a-tuple-in-map-directly/91575>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 12, 2022, 9:42pm UTC](https://discourse.julialang.org/t/why-i-cannot-use-a-tuple-in-map-directly/91575 "2022-12-12T21:42:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitsianis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pitsianis/32/26588_2.png) [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Post date:** [December 12, 2022, 9:42pm UTC](https://discourse.julialang.org/t/why-i-cannot-use-a-tuple-in-map-directly/91575/1 "2022-12-12T21:42:57Z")

</div>

Why I cannot do this

```julia
map((i,j,v) -> v/(i*j), zip([1,2],[10,20],[100,200]))

```

But this is just fine

```julia
[v/(i*j) for (i,j,v) in zip([1,2],[10,20],[100,200])]

```

And instead I have to write

```julia
map(x -> x[3]/(x[1]*x[2]), zip([1,2],[10,20],[100,200]))

```

which I consider unnecessary as they should be syntactic sugar from the same jar. 😉

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 12, 2022, 9:51pm UTC](https://discourse.julialang.org/t/why-i-cannot-use-a-tuple-in-map-directly/91575/2 "2022-12-12T21:51:16Z")

</div>

```julia
map(((i,j,v),) -> v/(i*j), zip([1,2],[10,20],[100,200]))

```

---

<div class="post-metadata">

**Author:** ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)\
**Post date:** [December 12, 2022, 9:51pm UTC](https://discourse.julialang.org/t/why-i-cannot-use-a-tuple-in-map-directly/91575/3 "2022-12-12T21:51:25Z")

</div>

You can use map, but the syntax is slightly different:

- `(i,j,v) -> v/(i*j)` is an anonymous function with three arguments, but `zip(x, y, z)` creates three tuples which map then passes to the function.

To make the example work, either

1. pass an anonymous function with a single argument destructuring into a three tuple:

```julia
map(((i,j,v),) -> v/(i*j), zip([1,2],[10,20],[100,200]))

```

2. or just pass all vectors as individual arguments to map (it will then call the function on three arguments instead of zipping them into three tuples):

```julia
map((i,j,v) -> v/(i*j), [1,2],[10,20],[100,200])

```

---

<div class="post-metadata">

**Author:** ![pitsianis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pitsianis/32/26588_2.png) [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Post date:** [December 13, 2022, 11:29am UTC](https://discourse.julialang.org/t/why-i-cannot-use-a-tuple-in-map-directly/91575/4 "2022-12-13T11:29:45Z")

</div>

Thank you both for clarifying my misunderstanding that a function that accepts a 3-tuple may also take three inputs and my ignorance that `map` accepts multiple collections.

I wonder whether the destructuring might be more _visible_ if a keyword `as` were used, for this example, `(t as (i,j,v)) -> v/(i*j)` to denote something like

```julia
t -> begin
  i, j, v = t
  v/(i*j)
end

```

similar to the grammar used in SML/NJ and Haskell to bind to a subpattern identifier.

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [December 13, 2022, 11:43am UTC](https://discourse.julialang.org/t/why-i-cannot-use-a-tuple-in-map-directly/91575/5 "2022-12-13T11:43:35Z")

</div>

The closest shape I can think of

```julia
map(t-> ((i,j,v)=t; v/(i*j)), zip([1,2],[10,20],[100,200]))

```
