hydra.overlay.python.lib.effects module

Python implementations of hydra.overlay.python.lib.effects primitives.

In Python the Hydra type effect<t> is transparent (the Python target lacks a TypeVariantEffect), so effect<t> is just t: effectful programs are ordinary eager native code and “running the effect” simply means forcing the value. These primitives therefore reduce to ordinary applications. See the Haskell reference implementation in Hydra.Haskell.Lib.Effects (where effect<t> = IO t). For #494.

hydra.overlay.python.lib.effects.apply(f: Callable[[A], B], a: A) B

Applicative apply for effects. Since effects are transparent, this just applies f to a.

hydra.overlay.python.lib.effects.bind(a: A, f: Callable[[A], B]) B

Sequence two effectful computations. Since effects are transparent, this just applies f to a.

hydra.overlay.python.lib.effects.compose(f: Callable[[A], B], g: Callable[[B], C], a: A) C

Kleisli composition for effects: run f, then g on its result.

hydra.overlay.python.lib.effects.fold_list(f: Callable[[A, B], A], acc: A, values: Sequence[B]) A

Left-fold over a list with an effect-returning function.

hydra.overlay.python.lib.effects.map(f: Callable[[A], B], a: A) B

Map a pure function over the result of an effect. Since effects are transparent, just apply f.

hydra.overlay.python.lib.effects.map_list(f: Callable[[A], B], values: Sequence[A]) tuple[B, ...]

Map an effect-returning function over a list, collecting the results.

hydra.overlay.python.lib.effects.map_optional(f: Callable[[A], B], x: object) object

Map an effect-returning function over an optional.

hydra.overlay.python.lib.effects.pure(a: A) A

Lift a pure value into an effect. Since effects are transparent, this is the identity.