Hi,
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
banana::Int
apple::Int
raspberry::Int
end
market = (banana=3, raspberry=4, apple=1)
split_fruits = Fruits(market...)
fields_fruits = Fruits(banana=market.banana, raspberry=market.raspberry, apple=market.apple)
## 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