Skip to content

Commit

Permalink
Add bag operators.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed Feb 19, 2012
1 parent 8488bba commit 49030d6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/CORE.setting
Expand Up @@ -2193,6 +2193,16 @@ sub bag(*@a) {
Bag.new(|@a);
}
proto sub infix:<⊍>($, $ --> Bag) is equiv(&infix:<X>) {*}
multi sub infix:<⊍>(Any $a, Any $b --> Bag) { bag($a) bag($b) }
multi sub infix:<⊍>(Bag $a, Bag $b --> Bag) { bag(($a $b).map({ ; $_ => $a{$_} min $b{$_} })) }
only sub infix:<(.)>($a, $b --> Bag) is equiv(&infix:<X>) { $a $b }
proto sub infix:<⊎>($, $ --> Bag) is equiv(&infix:<X>) {*}
multi sub infix:<⊎>(Any $a, Any $b --> Bag) { bag($a) bag($b) }
multi sub infix:<⊎>(Bag $a, Bag $b --> Bag) { bag(($a $b).map({ ; $_ => $a{$_} + $b{$_} })) }
only sub infix:<(+)>($a, $b --> Bag) is equiv(&infix:<X>) { $a $b }
class KeyBag does Associative {
has Int %!elems; # should be UInt
Expand Down

0 comments on commit 49030d6

Please sign in to comment.