Spectre.GAM.Kernel.Meter.Amounts (Spectre v0.4.0)

Copy Markdown View Source

Canonical shape for quantities bound to Meter references.

Constructors may accept a map or a list of reservation descriptors for host ergonomics. This module normalizes either form once to %{meter_ref => positive_integer}. Durable records and governed semantics use only that map thereafter, avoiding representation-dependent digests and repeated atom/string guessing inside the core.

Summary

Functions

Checks that partial quantities sum exactly to the total for each Meter.

Normalizes quantities and rejects an empty result.

Normalizes Meter quantities; the empty map is valid.

Types

t()

@type t() :: %{optional(String.t()) => pos_integer()}

Functions

exact_partition(total, left, right)

@spec exact_partition(t(), t(), t()) :: :ok | {:error, :invalid_meter_partition}

Checks that partial quantities sum exactly to the total for each Meter.

non_empty(amounts)

@spec non_empty(map() | list()) :: {:ok, t()} | {:error, term()}

Normalizes quantities and rejects an empty result.

normalize(amounts)

@spec normalize(map() | list()) :: {:ok, t()} | {:error, term()}

Normalizes Meter quantities; the empty map is valid.