Skip to content

Instantly share code, notes, and snippets.

@Xliff
Last active March 31, 2016 21:03
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 Xliff/2907106c84e9eb14d4c0 to your computer and use it in GitHub Desktop.
Save Xliff/2907106c84e9eb14d4c0 to your computer and use it in GitHub Desktop.
Match infix:<eqv> -- Draft!
multi sub infix:<eqv>(Match:D $a, Match:D $b) {
   $a.to   eqv $b.to   &&
   $a.from eqv $b.from &&
   $a.orig eqv $b.orig &&
   $a.made eqv $b.made &&
   $a.list eqv $b.list &&
   $a.hash eqv $b.hash;
}

A better implementation has been suggested:

multi sub infix:<eqv>(Match:D $a, Match:D $b) {
    [&&] (
        $a.to   eqv $b.to,
        $a.from eqv $b.from,
        $a.orig eqv $b.orig,
        $a.made eqv $b.made,
        $a.list eqv $b.list,
        $a.hash eqv $b.hash
    );
}

And that's where things currently stand.

@Xliff
Copy link
Author

Xliff commented Mar 31, 2016

Since most objects implement some operators as methods, how about this one for the Match class:

method eqv(Match:D: $b) {
        self === $b || [&&] (
                $!to      eqv $b.to,
                $!from    eqv $b.from,
                $!orig    eqv $b.orig,
                $!made    eqv $b.made,
                self.list eqv $b.list,
                self.hash eqv $b.hash
        );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment