data class State(
val userId: String, // the current user may change over time
val isHungry: Boolean, // user may become hungry over time
val currentTime: Int // hot code path, changes frequently
)
fun CoroutineScope.handleFirstStateForGoodPeople(states: Flow<State>) {
states
// when EACH user has `isHungry==true`
// I want to call a function
// but only the FIRST time this state is reached PER user (distinct by `userId`)
.onEachInternal { state -> callSomeFunction() }
.launchIn(this)
}