LangEx.Graph.State (LangEx v0.11.3)

Copy Markdown View Source

State management with reducer support.

Each key in the state schema can optionally have a reducer function (current_value, update_value) -> merged_value. Keys without reducers use last-write-wins semantics.

Summary

Functions

Applies a partial update to the current state using registered reducers. Keys present in update but absent from reducers use last-write-wins. Keys in update that don't exist in the current state are added.

Parses a schema keyword list into {initial_state, reducers}.

Types

reducers()

@type reducers() :: %{optional(atom()) => (any(), any() -> any())}

Functions

apply_update(current, update, reducers)

@spec apply_update(map(), map(), reducers()) :: map()

Applies a partial update to the current state using registered reducers. Keys present in update but absent from reducers use last-write-wins. Keys in update that don't exist in the current state are added.

parse_schema(schema)

@spec parse_schema(keyword()) :: {map(), reducers()}

Parses a schema keyword list into {initial_state, reducers}.

Schema entries are either:

  • key: default_value (no reducer, last-write-wins)
  • key: {default_value, reducer_fn} (custom reducer)