Replicating collections.Counter would be made easier by the addition of aggregation methods:
from cereggii import AtomicDict, NOT_FOUND
d = AtomicDict()
d.aggregate("spam", lambda current_value: 1 if current_value is NOT_FOUND else current_value + 1)
batch = [
("spam", 1),
("foo", 20),
]
def count(key, current, new):
if current is NOT_FOUND:
return 1
return current + new
d.reduce(batch, count)
Replicating
collections.Counter
would be made easier by the addition of aggregation methods: