Flexible design to extend or remove kwarg in functions

Lets say I am defining

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

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?

Some useful options are shown at

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

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
2 Likes