Change tracking library for frozen dataclasses
Project description
effect
Change tracking library for frozen dataclasses.
Get
pip install effectt
Example
from dataclasses import dataclass
from effect import (
Effect, Identified, LifeCycle, New, existing, just, new, mutated, Existing
)
@dataclass(kw_only=True, frozen=True, slots=True)
class A(Identified[str]):
id: str
line: str
@dataclass(kw_only=True, frozen=True, slots=True)
class X(Identified[str]):
id: str
a: A | None
number: int
type SomeX = (
Existing[X] # No effects / changes
| New[X] # Only `New[X]`
| Effect[X, A, X] # `New[A]` and `Mutated[X]`
)
def some_x_when(*, x: X | None, number: int) -> SomeX:
if x is None:
return new(X(id="X", a=None, number=number))
if x.a is not None:
return existing(x)
a = new(A(id="A", line=str()))
x = mutated(X(
id=x.id,
number=number,
a=just(a),
))
return a & x
# Or without `just`:
# return a.then(lambda a: mutated(X(
# id=x.id,
# number=number,
# a=a,
# )))
x = X(id="X", number=4, a=None)
some_x: LifeCycle[X | A] # All effects / changes for X and A
some_x = some_x_when(x=x, number=8)
assert just(some_x).number == 8
assert some_x.new_values == (A(id='A', line=''),)
assert some_x.mutated_values == (X(id='X', a=A(id='A', line=''), number=4),)
assert some_x.deleted_values == tuple()
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 Distribution
effectt-0.1.0.tar.gz
(20.8 kB
view details)
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
effectt-0.1.0-py3-none-any.whl
(12.1 kB
view details)
File details
Details for the file effectt-0.1.0.tar.gz.
File metadata
- Download URL: effectt-0.1.0.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9ecc3ab8ac0d5a51eb754de611e9938d3e7b0659d83d9ab773715eb2c52f8b5
|
|
| MD5 |
4f18cea26af4604fd30803223ef0d1a0
|
|
| BLAKE2b-256 |
1c77c5d8dd55a326fc1f442333942cd35007d89932bff81b53d7f3f04202b741
|
File details
Details for the file effectt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: effectt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f56fa3bb70512637e377ca06c0d8ecdc9a91ee55d29830b845eb2c7cbf9534d8
|
|
| MD5 |
909b5a18f1d9f259115102d57f6c9579
|
|
| BLAKE2b-256 |
7d6c2557e12c6070dea36c5903e193ab21cf3296768cb066ee8b97636d892941
|