-
-
Save smls/7a005bcc3716e993ae09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
class A { | |
has $.int is rw; | |
has @.AoA is rw; | |
has @.AoH is rw; | |
has %.HoH is rw; | |
method copy { | |
self.new( | |
int => $.int, | |
AoA => @.AoA.deepmap(*.clone), | |
AoH => @.AoH.deepmap(*.clone), | |
HoH => %.HoH.deepmap(*.clone), | |
) | |
} | |
}; | |
my $new = A.new( | |
int => 2, | |
AoA => [[2, 2], [2, 2]], | |
AoH => [{a => 2}, {a => 2}], | |
HoH => {a => {a => 2}}, | |
); | |
my $copy = $new.copy; | |
$new.int = 4; | |
$new.AoA[0][0] = 4; | |
$new.AoH[0]<a> = 4; | |
$new.HoH<a><a> = 4; | |
dd $new, $copy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$new = A.new(int => 4, AoA => [[4, 2], [2, 2]]<>, AoH => [{:a(4)}, {:a(2)}]<>, HoH => {:a({:a(4)})}<>) | |
$copy = A.new(int => 2, AoA => [[2, 2], [2, 2]]<>, AoH => [{:a(2)}, {:a(2)}]<>, HoH => {:a({:a(2)})}<>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment