# Splat ComponentArray into keyword arguments

**URL:** https://discourse.julialang.org/t/splat-componentarray-into-keyword-arguments/75003
**Category:** General Usage
**Tags:** question, componentarrays
**Created:** [January 21, 2022, 8:14pm UTC](https://discourse.julialang.org/t/splat-componentarray-into-keyword-arguments/75003 "2022-01-21T20:14:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)
#### Post date: [January 21, 2022, 8:14pm UTC](https://discourse.julialang.org/t/splat-componentarray-into-keyword-arguments/75003/1 "2022-01-21T20:14:01Z")

</div>

Hi all,

I have a situation in which “splatting” a ComponentArray into keyword arguments would be useful. Unfortunately, it is not currently possible. I was wondering whether it would be possible in principle? Could I add that capability?

**MWE**

```julia
using ComponentArrays

x = ComponentArray(a = 1, b = 2)

f(;a, b) = a + b

f(;x...)

```

---

<div class="post-metadata">

### Author: ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)
#### Post date: [January 21, 2022, 8:21pm UTC](https://discourse.julialang.org/t/splat-componentarray-into-keyword-arguments/75003/2 "2022-01-21T20:21:34Z")

</div>

That might be a good thing to add. It looks like it may only need a `merge` method defined. Would you mind opening up an issue for that?

In the meantime, though, you could always do something like:

```julia
julia> f(; NamedTuple(x)...)
3

```

---

<div class="post-metadata">

### Author: ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)
#### Post date: [January 21, 2022, 8:30pm UTC](https://discourse.julialang.org/t/splat-componentarray-into-keyword-arguments/75003/3 "2022-01-21T20:30:23Z")

</div>

Awesome. I will add an issue. Thanks!

---

<div class="post-metadata">

### Author: ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)
#### Post date: [January 21, 2022, 8:51pm UTC](https://discourse.julialang.org/t/splat-componentarray-into-keyword-arguments/75003/4 "2022-01-21T20:51:28Z")

</div>

> [@jonniedie](#):
>
> `f(; NamedTuple(x)...)`

Although converting to a `NamedTuple` does work, it does add some overhead. Out of curiosity, would your more permanent solution with `merge` be more efficient?

---

<div class="post-metadata">

### Author: ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)
#### Post date: [January 21, 2022, 9:03pm UTC](https://discourse.julialang.org/t/splat-componentarray-into-keyword-arguments/75003/5 "2022-01-21T21:03:53Z")

</div>

Unfortunately `merge` is going to have to convert to `NamedTuple` to perform the merge with the empty `NamedTuple` anyway (which is how keyword argument splatting works). I don’t think there is any way to buy into the keyword arg splatting without doing this. Maybe I’m wrong, though. Might be worth checking.
