kotlin-flow-state-event-modeling
Installation
SKILL.md
Kotlin Flow: state and event modeling
Core principle
Pick the primitive that matches replay, fan-out, and synchronous-read requirements. StateFlow, SharedFlow, Channel-backed flows, and cold Flow differ in buffering, who sees each emission, and whether .value exists. Wrong choices drop events, leak sharing coroutines, or force fake domain sentinels into state.
When to use this skill
You're writing or reviewing Kotlin code involving:
MutableStateFlow<T>(SomeSentinel)—NoUser,Empty,Loading, etc. — because the real value is async.stateIn(...)called inside a function rather than assigned to a propertySharingStarted.WhileSubscribed(...)on a flow whose.valueis read synchronously and must stay freshMutableSharedFlowfor navigation events, snackbars, or other one-shot emissions where loss would be a bug.map { }on aStateFlowwhen consumers still need synchronous.valueMutableStateFlow.value = _state.value.copy(...)or update code that builds expensive objects insideupdate { ... }