# How to ignore unnecessary function arguments?

**URL:** <https://discourse.julialang.org/t/how-to-ignore-unnecessary-function-arguments/91440>\
**Category:** General Usage\
**Created:** [December 8, 2022, 6:46pm UTC](https://discourse.julialang.org/t/how-to-ignore-unnecessary-function-arguments/91440 "2022-12-08T18:46:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [December 8, 2022, 6:46pm UTC](https://discourse.julialang.org/t/how-to-ignore-unnecessary-function-arguments/91440/1 "2022-12-08T18:46:50Z")

</div>

```julia
# Hello, i have any structures with kwargs, like this
Base.@kwdef struct Foo
  a
  b
  c
end

# and i have any named tuples like this
nt = (a=1, b=2, c=3, d=4, e=5, f=6, g=7) # ...

# always :
issubset(fieldnames(Foo), keys(nt )) # -> true

# is there a universal way to ignore unnecessary arguments???
Foo(; nt...) # -> ERROR: MethodError: ...

```

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [December 8, 2022, 7:12pm UTC](https://discourse.julialang.org/t/how-to-ignore-unnecessary-function-arguments/91440/2 "2022-12-08T19:12:42Z")

</div>

By universal, are you trying to match the parameter names of a given struct to those of a named tuple? And have an instance be built based on indexing the named tuple for the same parameter names?

Two quick solutions come to mind:

```julia
Foo(nt[:a], [:b], [:c])

```

And this generic one.

```julia
foo_vals = filter(x -> in(x, fieldnames(Foo)), keys(nt))
Foo(nt[foo_vals]...)

```

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [December 8, 2022, 7:26pm UTC](https://discourse.julialang.org/t/how-to-ignore-unnecessary-function-arguments/91440/3 "2022-12-08T19:26:18Z")

</div>

I’d just write

```julia
Foo(;a, b, c, kwargs...) = Foo(a, b, c)

```

that way, `Foo(; nt...)` works.
