Field insertion in immutable @with_kw struct

I am trying to load a @with_kw struct from a named tuple, but I cannot find a way to associate the fields correctly.
I would like to use something like a split operator, but the split operator on a named tuple return only the values. I am sure there is a way of doing this, can you help me?

I could use a for loop on the fieldnames, but my struct is immutable.

using Parameters

@with_kw struct Fruits

market = (banana=3, raspberry=4, apple=1)

split_fruits = Fruits(market...)
fields_fruits = Fruits(banana=market.banana, raspberry=market.raspberry,

## check the cart
_samestuff(m, f, field)= getfield(m, field) == getfield(f, field)
samestuff(market, fruits) =  all([_samestuff(market,fruits,field) for field in fieldnames(Fruits) ])

split_operator = samestuff(market,split_fruits)
field_assignment = samestuff(market,fields_fruits)

print("The split operator works: $split_operator \n")
print("The field assignment works: $field_assignment")

## output
The split operator works: false 
The field assignment works: true

I think you want

julia> Fruits(; market...)
  banana: Int64 3
  apple: Int64 1
  raspberry: Int64 4

this splats market as keyword arguments, whereas your version splats it as positional arguments, in which case you just get the order in which the values show up:

julia> println(market...)
1 Like

yes, thanks!