Core API Reference
Reference for evaluating features and retrieving explainable decisions.
Feature.evaluate(context, registry): T
Standard evaluation API.
fun <T : Any, C : Context, M : Namespace> Feature<T, C, M>.evaluate(
context: C,
registry: NamespaceRegistry = namespace,
): T
-
Guarantee: Returns a value of type
Tand never returnsnull. -
Mechanism: Evaluation returns the first matching rule value or the declared default.
-
Boundary: Throws
IllegalStateExceptionif the feature is not registered in the registry.
Example
val enabled: Boolean = AppFeatures.darkMode.evaluate(context)
Behavior
- Resolve the feature definition from the registry.
- If the registry kill-switch is enabled, return the default.
- If the flag is inactive, return the default.
- Evaluate rules by descending specificity.
- Apply ramp-up to the first matching rule.
- Return the rule value or the default.
Advanced Options
Feature.explain(context, registry): EvaluationResult<T>
Explainable evaluation for debugging and observability.
fun <T : Any, C : Context, M : Namespace> Feature<T, C, M>.explain(
context: C,
registry: NamespaceRegistry = namespace,
): EvaluationResult<T>
Example
val result = AppFeatures.darkMode.explain(context)
when (val decision = result.decision) {
EvaluationResult.Decision.RegistryDisabled -> println("Registry disabled")
EvaluationResult.Decision.Inactive -> println("Flag inactive")
is EvaluationResult.Decision.Rule -> println("Matched: ${decision.matched.rule.note}")
is EvaluationResult.Decision.Default -> println("Default returned")
}
Feature.evaluateWithReason(...)
Deprecated alias for explain(...).
@Deprecated("Use explain() instead")
fun <T : Any, C : Context, M : Namespace> Feature<T, C, M>.evaluateWithReason(
context: C,
registry: NamespaceRegistry = namespace,
): EvaluationResult<T>