# Concise unpacking syntax

**URL:** <https://discourse.julialang.org/t/concise-unpacking-syntax/74004>\
**Category:** General Usage\
**Tags:** namedtuple, functions\
**Created:** [January 3, 2022, 9:49pm UTC](https://discourse.julialang.org/t/concise-unpacking-syntax/74004 "2022-01-03T21:49:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [January 3, 2022, 9:49pm UTC](https://discourse.julialang.org/t/concise-unpacking-syntax/74004/1 "2022-01-03T21:49:04Z")

</div>

I have a namedtuple `data = (;a=1,b=2,c=3)` and a function `f` that takes kwargs `;a,b`. I want to call `f` with `f(;a,b)`

```julia
f(;a,b) = a+b
data = (;a=1,b=2,c=3)
(;a,b) = data
f(;a,b)

```

But there I have to specify `a` and `b` twice: once in the unpacking and once at the call site. Is it possible to specify them only once?

I tried something like this but not right.

```julia
data2 = (;a,b) = data
f(data2...)

```

nor

```julia
f(((;a,b) = data)...)

```

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [January 3, 2022, 10:08pm UTC](https://discourse.julialang.org/t/concise-unpacking-syntax/74004/2 "2022-01-03T22:08:31Z")

</div>

Note that for the splatting into kwargs you need a `;`.  
However, your later tries also do not work with an added `;` as an assignment returns the right-hand-side.

This works:

```julia
julia> f(;a,b,kw...) = a+b
f (generic function with 1 method)

julia> f(;data...)
3

```

but may not be quite what you’d like.

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [January 3, 2022, 10:10pm UTC](https://discourse.julialang.org/t/concise-unpacking-syntax/74004/3 "2022-01-03T22:10:32Z")

</div>

That requires changing the function, which isn’t what I want.

```julia
julia> f(;((;a,b) = data)...)
ERROR: MethodError: no method matching f(; a=1, b=2, c=3)

```

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [January 3, 2022, 10:16pm UTC](https://discourse.julialang.org/t/concise-unpacking-syntax/74004/4 "2022-01-03T22:16:00Z")

</div>

This should work: `f(; data[(:a, :b)]...)`.
