Is there something like the get() function for namedTuples?

Is there an equivalent of the get() function for dictionaries for NamedTuples?
I want to get the value for the ‘key’ of a NamedTuple if it exists, and if it does not assign it to some default value; pretty much exactly what the get() function does with dictionaries.

This already works (since v1.7):

julia> get((a = 2, b = 3), :c, 4)
help?> get
search: get get! getpid getkey getfield getindex getglobal getproperty gethostname get_zero_subnormals

  get(collection, key, default)

  Return the value stored for the given key, or the given default value if no mapping for the key is present.

  │ Julia 1.7
  │  For tuples and numbers, this function requires at least Julia 1.7.
1 Like

Thank you! I was trying it as "c" instead of :c .