# Is there a \`with\` operator or usage pattern?

**URL:** <https://discourse.julialang.org/t/is-there-a-with-operator-or-usage-pattern/52693>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 1, 2021, 1:05pm UTC](https://discourse.julialang.org/t/is-there-a-with-operator-or-usage-pattern/52693 "2021-01-01T13:05:06Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [January 1, 2021, 5:29pm UTC](https://discourse.julialang.org/t/is-there-a-with-operator-or-usage-pattern/52693/11 "2021-01-01T17:29:17Z")

</div>

If we could generate a function `f` as below, then you could just splat the `NamedTuple` into the keyword parameters of `f`

```julia
subtotal = (price=12.99, shipping=3.99)
f(; price, shipping) = price + shipping
f(; subtotal ...) # 16.98

```

I feel like I’m almost there:

```julia
julia> subtotal = (price=12.99, shipping=3.99)
(price = 12.99, shipping = 3.99)

julia> function genfunc(nt, body)
           local props = propertynames(nt)
               f = :( (; $(props...) )-> $body )
           g = Meta.eval(f)
           Base.invokelatest(g; nt...)
       end
genfunc (generic function with 1 method)

julia> genfunc(subtotal, quote
           shipping + price
       end)
16.98

```

---

_[View the full topic](https://discourse.julialang.org/t/is-there-a-with-operator-or-usage-pattern/52693)._
