# Flexible design to extend or remove kwarg in functions

**URL:** https://discourse.julialang.org/t/flexible-design-to-extend-or-remove-kwarg-in-functions/91644
**Category:** General Usage
**Created:** [December 14, 2022, 3:48pm UTC](https://discourse.julialang.org/t/flexible-design-to-extend-or-remove-kwarg-in-functions/91644 "2022-12-14T15:48:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@Thomas](https://discourse.julialang.org/u/Thomas)
#### Post date: [December 14, 2022, 3:48pm UTC](https://discourse.julialang.org/t/flexible-design-to-extend-or-remove-kwarg-in-functions/91644/1 "2022-12-14T15:48:00Z")

</div>

Lets say I am defining

```julia
outer_func(x; verbose=true) = (y=1;inner_func(x,y, verbose=verbose)
inner_func(x,y; verbose=false) = (z=x+y;verbose && println(z);z^2)

```

Now I would like to add two kwargs, manually like this

```julia
outer_func(x; verbose=true, check=true, algo=:fast)
inner_func(x,y; verbose=false, check=false, debug=false)

```

Can I do this in a more flexible and controllable ways when the number of kwargs added is large (something like `outer_func(x; verbose=true, kwargs...)` then I pass `kwargs` to the inner function)?

Next, what if I have a certain design and want to remove kwargs?

---

<div class="post-metadata">

### Author: ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)
#### Post date: [December 14, 2022, 6:25pm UTC](https://discourse.julialang.org/t/flexible-design-to-extend-or-remove-kwarg-in-functions/91644/2 "2022-12-14T18:25:29Z")

</div>

Some useful options are shown at

> [@How to use \`kwargs\` to avoid passing around keyword arguments?](https://discourse.julialang.org/t/how-to-use-kwargs-to-avoid-passing-around-keyword-arguments/84856):
>
> I found the documentation on kwargs to be a little terse… how can I exploit keyword arguments to avoid copying tons of different keyword arguments when passing them function to function? my example below. seems unnatural to write out so many keyword arguments and keep track of them in two places. or is this what needs done? note \_viz\_posterior\_fit! will be called elsewhere. thx for tips/insights. will pass on to my students slight_smile function \_viz\_posterior\_fit!(ax::Axis, data::DataFrame,…

The suggestion to package large numbers of kwargs into a `struct` makes sense to me.  
I also like the “merge defaults” pattern:

```julia
function foo(; kwargs...)
   # Note that `x = 17` works as well as `:x => 17`
   defaults = (x = 17, );
   args = merge(defaults, kwargs);
   println(args[:x])
   # Or call another function `bar(; args...)`
end

```
