A Python package for reducing mapping-like objects using reducer objects, implemented in Rust.
Project description
event-sourcer
Example use
from event_sourcer import reduce_dict
class SumReducer:
def init(self):
return 0
def update(self, acc, value):
return acc + value
def finalize(self, acc):
return acc
class AvgReducer:
def init(self):
return (0, 0) # (total, count)
def update(self, acc, value):
total, count = acc
return (total + value, count + 1)
def finalize(self, acc):
total, count = acc
return total / count if count else None
# Any object supporting __getitem__ will work; here we use dicts.
def generate_objects():
yield {"a": 1, "b": 4}
yield {"a": 1, "c": 4}
reducers = {
"a": SumReducer(),
"b": AvgReducer(),
"c": AvgReducer(),
"d": SumReducer(),
}
result = reduce_dict(generate_objects(), reducers)
print(result)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dict_sourcer-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: dict_sourcer-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 239.6 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5354ad040b078e7072ce0bc325a330f9347999697fb36c08b36aa0b4ed89fbdc
|
|
| MD5 |
70a9b87f383e2c22048f4101c6fddcab
|
|
| BLAKE2b-256 |
142a24f2fbf4d7d7525fd5a00f2dcd23ffd9b7cb7d57f11f89fe404dfc9cbf1f
|