Doubtless the original poster expected aBag asDictionary
to answer a dictionary mapping the (distinct) elements of
the bag to their counts.�� Mathematically, a bag can
usefully be seen as a partial function from a set U to
the positive integers, and a dictionary with U keys and
positive integer values is precisely that.
It's really not unreasonable to expect that,
considering that there *is* a method that does just
what the OP wanted: #valuesAndCounts.�� It's rather
dangerous to expose private state like that, but it
is not a private method.�� I would expect
asDictionary
�� ^contents copy