Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge Hash (Raku)

Tags:

raku

FAQ, Int Raku, how to merge, combine two hashes?

Say:

my %a = 1 => 2;
my %b = 3 => 4, 5 => 6

How to get %c = 1 => 2, 3 => 4, 5 => 6 ?

like image 508
Tinmarino Avatar asked Mar 26 '20 18:03

Tinmarino


1 Answers

  1. Use Slip prefix |
  2. Use append Hash method
  3. Use infix , operator

Assuming:

my %a = 1 => 'a', 3 => 4;
my %b = 1 => 'b', 5 => 6;
say %(|%a, |%b);  # {1 => b, 3 => 4, 5 => 6}
say %().append(%a).append(%b);  # {1 => [a b], 3 => 4, 5 => 6}
my %c = %a, %b; say(%c);  # {1 => b, 3 => 4, 5 => 6}
like image 103
Tinmarino Avatar answered Oct 23 '22 20:10

Tinmarino