polix.effects.core
Core API for applying effects to state.
Effects are pure data structures describing state mutations. This namespace provides apply-effect as the primary entry point for effect application, with optional schema validation.
Built-in effect types use the :polix.effects/* namespace: - :polix.effects/noop - Does nothing - :polix.effects/sequence - Applies effects in order - :polix.effects/assoc-in - Sets a value at a path - :polix.effects/update-in - Updates a value at a path with a function - :polix.effects/dissoc-in - Removes a value at a path - :polix.effects/merge-in - Merges a map at a path - :polix.effects/conj-in - Adds to a collection at a path - :polix.effects/remove-in - Removes from a collection by predicate - :polix.effects/move - Moves items between collections - :polix.effects/transaction - Atomic application with rollback - :polix.effects/let - Binds values for nested effects - :polix.effects/conditional - Branching based on polix conditions
Domain-specific effects can be registered via register-effect!.
apply-effect
(apply-effect state effect)(apply-effect state effect ctx)(apply-effect state effect ctx opts)Applies an effect to state within context.
Takes a state map, an effect data structure, an optional context map, and optional options. Returns a result map with:
:state- The new state after applying the effect:applied- Vector of effects that were successfully applied:failed- Vector of{:effect ... :error ... :message ...}for failures:pending- Nil, or pending choice info
The context map can contain: - :bindings - Map of symbolic bindings (:self, :target, etc.) - :source - Identifier of what initiated this effect
Options: - :validate? - Validate effect against schema (default true)
apply-effects
(apply-effects state effects)(apply-effects state effects ctx)(apply-effects state effects ctx opts)Applies multiple effects in sequence.
Equivalent to wrapping effects in a :polix.effects/sequence effect. Stops on first pending effect. Accumulates all applied and failed effects.
default-resolver
The default reference resolver. See polix.effects.resolution/default-resolver.
effect-types
Returns set of registered effect types. See polix.effects.registry/effect-types.
failure
Creates a failed result. See polix.effects.registry/failure.
register-effect!
Registers a custom effect handler. See polix.effects.registry/register-effect!.
resolve-fn
Resolves a function reference. See polix.effects.resolution/resolve-fn.
resolve-predicate
Resolves a predicate specification. See polix.effects.resolution/resolve-predicate.
resolve-ref
Resolves a reference within context. See polix.effects.resolution/resolve-ref.
success
Creates a successful result. See polix.effects.registry/success.
validate-effect
(validate-effect effect)Validates an effect against the schema.
Returns nil if valid, or an explanation map if invalid.