Your First Feature
This guide builds one feature end-to-end: definition, targeting rules, and evaluation.
1) Define a namespace and a feature
import io.amichne.konditional.context.*
object AppFeatures : Namespace("app") {
val darkMode by boolean<Context>(default = false) {
rule(true) { platforms(Platform.IOS) }
rule(true) { locales(AppLocale.UNITED_STATES) }
}
}
2) Create a context and evaluate
val ctx = Context(
locale = AppLocale.UNITED_STATES,
platform = Platform.IOS,
appVersion = Version.of(2, 0, 0),
stableId = StableId.of("user-123"),
)
val enabled: Boolean = AppFeatures.darkMode.evaluate(ctx)
If no rule matches, the default value is returned.
What just happened
- A Namespace is a registry of features.
- A Feature is a typed value with rules.
- A Rule is criteria -> value mapping.
- A Context provides runtime inputs used by rules.
Guarantees
-
Guarantee: Evaluation always returns a non-null value of the declared type.
-
Mechanism: Features require a
defaultvalue and return it when no rule matches. -
Boundary: Konditional does not validate business logic; it only evaluates rules.
Next steps
- Learn the core concepts: Core Concepts
- Understand rule ordering and ramp-ups: Evaluation Model