I must say I somewhat disagree with the terminology. The requested operation is an update not a merge. Demonstrate both an update and a merge. Associative arrays are commonly called hashes in Raku.
# Show original hashessaymy %base = :name('Rocket Skates'), :price<12.75>, :color<yellow>;saymy %update = :price<15.25>, :color<red>, :year<1974>;# Need to assign to anonymous hash to get the desired results and avoid mutating# TIMTOWTDIsay"\nUpdate:\n", join"\n", sort %=%base, %update;# Samesay"\nUpdate:\n", {%base, %update}.sort.join: "\n";say"\nMerge:\n", join"\n", sort ((%=%base).push: %update)».join: ', ';# Samesay"\nMerge:\n", ({%base}.push: %update)».join(', ').sort.join: "\n";# Demonstrate unmutated hashessay"\n", %base, "\n", %update;
Output:
{color => yellow, name => Rocket Skates, price => 12.75}
{color => red, price => 15.25, year => 1974}
Update:
color red
name Rocket Skates
price 15.25
year 1974
Update:
color red
name Rocket Skates
price 15.25
year 1974
Merge:
color yellow, red
name Rocket Skates
price 12.75, 15.25
year 1974
Merge:
color yellow, red
name Rocket Skates
price 12.75, 15.25
year 1974
{color => yellow, name => Rocket Skates, price => 12.75}
{color => red, price => 15.25, year => 1974}