Skip to content

Instantly share code, notes, and snippets.

@moritz
Created September 5, 2013 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/6455428 to your computer and use it in GitHub Desktop.
Save moritz/6455428 to your computer and use it in GitHub Desktop.
Object eqvuivalence
multi sub infix:<eqv>(Any:D $a, Any:D $b) is default {
return False unless $a.WHAT === $b.WHAT;
for $a.^attributes.grep(*.has_accessor) -> $attr {
my $name = $attr.name.substr(2);
return False unless $a."$name"() eqv $b."$name"();
}
True;
}
class A {
has $.x;
}
say A.new(x => 1) eqv A.new(x => 2);
say A.new(x => 2) eqv A.new(x => 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment