Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AtomicDict.reduce(), AtomicDict.aggregate() #24

Open
dpdani opened this issue May 12, 2024 · 0 comments
Open

Add AtomicDict.reduce(), AtomicDict.aggregate() #24

dpdani opened this issue May 12, 2024 · 0 comments

Comments

@dpdani
Copy link
Owner

dpdani commented May 12, 2024

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)
@dpdani dpdani changed the title Add AtomicDict.aggregate() Add AtomicDict.reduce(), AtomicDict.aggregate() Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant