Skip to content
Logo

Building effects

E.(21).(lambda :  * 2)  # Effect[int]
 
E.(lambda: ("hi"))  # Effect[None] — defers a side effect until the effect runs
 
 
# Custom errors extend EffectonError and are final: one leaf class per cause
@
@(frozen=True)
class (E.):
    : 
 
 
E.((msg="oops"))  # Effect[Never, OopsError]

suspend defers building an effect. The thunk form wraps one effect; as a decorator on a function with parameters, each call captures its arguments and defers the body until the effect runs:

E.(lambda: E.((msg="later")))  # Effect[Never, OopsError]
 
 
@E.
def (: ) -> E.[, ]:
    ("runs only when the effect is interpreted")
    return E.(f"user-{}")
 
 
(1)  # Effect[str, OopsError] — nothing printed yet

More examples: test_run_sync.py, test_suspend.py.