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.
Create an empty bag.
Create a bag with n copies of a value.
Insert n copies of a value into a 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', 'a', 'b']
remove 3 'a' bag == fromList ['b']Determine if a bag is empty.
Determine if a value is in a bag.
Determine the number of copies of a value in a bag.
Determine the number of values in a bag.
Get 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 a list, sorted from lowest to highest.
Convert a list into a bag.
Map a function onto a bag, creating a new bag.
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.
Create two new bags; the first consisting of values which satisfy a predicate, the second consisting of values which do not.
A set of possibly multiple values.