I'm trying to represent something of the form "I've chosen one member of this group, three members of that group, and nobody from the other group". A Bag seems right for this, except that if I want to get the list of groups, it doesn't seem to include the one with nobody:
> Bag.new-from-pairs('a' => 0, 'b' => 3) bag(b(3)) > my $b = BagHash.new() BagHash.new() > $b<a> = 3 3 > $b BagHash.new(a(3)) > $b<a> = 0 0 > $b BagHash.new() I was hoping for something like Python's Counter: >>> Counter({'a': 0, 'b': 3}) Counter({'b': 3, 'a': 0}) >>> b = Counter() >>> b['a'] = 2 >>> b Counter({'a': 2}) >>> b['a'] = 0 >>> b Counter({'a': 0}) I'm wondering if anyone has any bright ideas related to this. Two things come to mind for myself: I could subclass Bag (or create a new implementation of Baggy), but I'm not entirely sure how I'd do so sensibly (i.e. without reimplementing basically the whole of Bag - operators, initializers, stringifiers...); or I could create a new class which basically contains nothing but a list and a bag whose keys are elements of the list. Thanks, Phil