Permalink
Browse files

Implement masak's proposed Hash comparison.

  • Loading branch information...
1 parent d8852de commit 55f5b8a406e13a55ae8d4b206118755418eaf2d4 @colomon colomon committed Sep 24, 2012
Showing with 10 additions and 0 deletions.
  1. +10 −0 lib/CORE.setting
View
@@ -3329,6 +3329,16 @@ sub infix:<cmp> is equiv<leg> (Mu $a, Mu $b) {
}
return $a <=> $b;
}
+ if $a ~~ Hash {
+ my $keys = set $a.keys, $b.keys;
+ my @keys = $keys.keys.sort;
+ for @keys -> $k {
+ return Order::Decrease unless $a{$k} :exists;
+ return Order::Increase unless $b{$k} :exists;
+ (my $r = $a{$k} cmp $b{$k}) && return $r;
+ }
+ return Order::Same;
+ }
return $a <=> $b;
}
sub infix:<eqv> is equiv<==> (Any $a, Any $b) { ($a.WHAT.gist cmp $b.WHAT.gist) == 0 && ($a cmp $b) == 0 }

0 comments on commit 55f5b8a

Please sign in to comment.