Skip to content

Commit

Permalink
[Set] implemented .symmetricdifference and (^)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Sep 2, 2010
1 parent dc99008 commit d75c61d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/Set.pm
Expand Up @@ -54,6 +54,13 @@ class Set does Associative {
self.new(grep { !contains(@otherset, $_) }, @!elems);
}

multi method symmetricdifference(%otherset) {
self.symmetricdifference(%otherset.keys);
}
multi method symmetricdifference(@otherset) {
self.difference(@otherset).union(Set.new(@otherset).difference(self));
}

multi method subsetorequal(@otherset) {
?contains(@otherset, all(@!elems));
}
Expand Down Expand Up @@ -100,6 +107,11 @@ our multi sub infix:<(-)>( %a, %b) { Set.new( %a).difference(%b) }
our multi sub infix:<(-)>( @a, %b) { Set.new(|@a).difference(%b) }
our multi sub infix:<(-)>( @a, @b) { Set.new(|@a).difference(@b) }

our multi sub infix:<(^)>(Set $a, %b) { $a.symmetricdifference(%b) }
our multi sub infix:<(^)>( %a, %b) { Set.new( %a).symmetricdifference(%b) }
our multi sub infix:<(^)>( @a, %b) { Set.new(|@a).symmetricdifference(%b) }
our multi sub infix:<(^)>( @a, @b) { Set.new(|@a).symmetricdifference(@b) }

our multi sub infix:<(<=)>(Set $a, %b) { $a.subsetorequal(%b) }
our multi sub infix:<(<=)>( %a, %b) { Set.new( %a).subsetorequal(%b) }
our multi sub infix:<(<=)>( @a, %b) { Set.new(|@a).subsetorequal(%b) }
Expand Down

0 comments on commit d75c61d

Please sign in to comment.