kumulant

StatSpec

@Serializable
sealed interface StatSpec(source)

Pure-data recipe for a com.eignex.kumulant.core.Stat. Each variant is a data class (or data object for parameter-less stats) whose fields are exactly the stat's configuration surface - no live cells, no locks, no com.eignex.kumulant.core.Concurrency.

Polymorphism is by @SerialName on each variant, so any kotlinx.serialization format that supports open polymorphism works. Defaults on each spec match the corresponding stat's constructor defaults so encoded payloads stay terse when the format is configured with encodeDefaults = false.

Construction of the live stat happens externally via the materialize extension functions in StatFactory.kt - one when per modality, one cast at the boundary. Specs stay as pure data so the wire format doesn't drag behaviour through it. com.eignex.kumulant.core.Concurrency is not on the wire - it's a deployment knob passed in at materialize time.

The generic <R> on the modality-specific spec interfaces is a phantom marker: it carries the result type through the schema declarators (series(spec): StatKey<R>) and the materialize return type, but it does not appear in the wire format.

Samples

val spec: StatSpec = Mean
val json = SchemaJson.encodeToString(spec)
val decoded = SchemaJson.decodeFromString<StatSpec>(json)
val live = (decoded as SeriesStatSpec<WeightedMeanResult>).materialize(Concurrency.None)
live.update(1.0)

Inheritors

Functions

Link copied to clipboard
fun StatSpec.materialize(concurrency: Concurrency = Concurrency.None): Stat<*>

Construct a live stat from any StatSpec, dispatching on its modality. Useful for code paths (like StatSchemaDef.materialize) that iterate over an erased Map<String, StatSpec> and don't statically know the modality.