Jido.Memory.Space (Jido v2.0.0-rc.4)

View Source

The unit of memory — a named container with typed data and revision tracking.

A Space holds either a map (key-value) or list (ordered items) in its data field. The type is determined by the data itself — pattern matching and guards (is_map/1, is_list/1) handle dispatch.

Each space tracks its own revision counter independently, enabling fine-grained concurrency control.

Examples

# Key-value space (world model)
world = Space.new_kv()
world = %{world | data: Map.put(world.data, :temperature, 22)}

# List space (task list)
tasks = Space.new_list()
tasks = %{tasks | data: tasks.data ++ [%{id: "t1", text: "Check sensor"}]}

Summary

Functions

Returns true if the space holds list data.

Returns true if the space holds map data.

Create a new space from attributes.

Create a new key-value (map) space.

Create a new list space.

Returns the Zoi schema for Space.

Types

t()

@type t() :: %Jido.Memory.Space{data: any(), metadata: map(), rev: integer()}

Functions

list?(space)

@spec list?(t()) :: boolean()

Returns true if the space holds list data.

map?(space)

@spec map?(t()) :: boolean()

Returns true if the space holds map data.

new(attrs)

@spec new(map() | keyword()) :: t()

Create a new space from attributes.

new_kv(opts \\ [])

@spec new_kv(keyword()) :: t()

Create a new key-value (map) space.

new_list(opts \\ [])

@spec new_list(keyword()) :: t()

Create a new list space.

schema()

@spec schema() :: Zoi.schema()

Returns the Zoi schema for Space.