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.1.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.1-py3-none-any.whl
(12.3 kB
view details)
File details
Details for the file effectt-0.1.1.tar.gz.
File metadata
- Download URL: effectt-0.1.1.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 |
456c56b1e6935ba3aef22168fb618bacb9908587c57a7aea0da4154e0789ec27
|
|
| MD5 |
84b5dcb044a6ccd3b0c65931e40ed5a4
|
|
| BLAKE2b-256 |
3830ea51f40bdb13406d735b2e1ee7034587083a765fd1af397a7b83e297da04
|
File details
Details for the file effectt-0.1.1-py3-none-any.whl.
File metadata
- Download URL: effectt-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25033fb842716564803a5d8774654bec743a8ad0b1e9733d1d6a8fe69d7d439f
|
|
| MD5 |
a4cd15d9bb6855f26351e0f38d1ef74c
|
|
| BLAKE2b-256 |
651ca068bf70f4c7263f41c9dbfbc1fab10c7c439e64958c52c90900be63a442
|