A set of values where, unlike Set, each value can appear multiple times.
It's basically just a fancy wrapper for Dict, so like Dict,
insert, remove, and query operations all take O(log n) time.
Insert n copies of a value into a bag. If n is negative, then it removes -n copies of the value from the bag.
Remove n copies of a value from a bag. If n is greater than the numbers of copies that are in the bag, then all copies are simply removed.
bag = fromList [('a',2),('b',1)]
remove 3 'a' bag == fromList [('b',1)]If n is negative, then it inserts -n copies of the value into the bag.
Determine the number of values in a bag.
bag = fromList [('a',2),('b',1)]
size bag == 3Get the union of two bags. For a value, its two counts are added.
Get the intersection of two bags. For a value, the lesser of its two counts is taken.
Get the difference between of two bags. For a value, the count of the second is removed from the count of the first.
Convert a bag into an association list, sorted from lowest to highest.
Convert an association list into a bag.
Map a function onto a bag, creating a new bag. If keys clash after mapping, their counts are simply added.
bag = fromList [('a',2),('b',1)]
map (always 'c') bag == fromList [('c',3)]Fold over the values in a bag, in order from lowest to highest.
Fold over the values in a bag, in order from highest to lowest
Create a new bag consisting only of values which satisfy a predicate.
A set of possibly multiple values.