select

inline fun <T : ModuleState, R> select(crossinline selector: (T) -> R, noinline areEqual: (R, R) -> Boolean = { old, new -> old == new }): State<R>(source)

Creates derived state from a module state using a selector function.

This is useful when you only need a subset of the state. The composable will only recompose when the selected value changes, not when other parts of the state change.

Example:

@Composable
fun TodoCount() {
// Only recomposes when the count changes, not when other TodoState fields change
val count by select<TodoState, Int> { state -> state.items.size }
Text("$count items")
}

// With custom equality
@Composable
fun UserDisplay() {
val userName by select<UserState, String>(
selector = { it.user?.name ?: "Guest" },
areEqual = { old, new -> old == new }
)
Text("Hello, $userName")
}

Return

Compose State of the derived value type

Parameters

selector

Function to extract the derived value from the state

areEqual

Custom equality function for comparing values (defaults to ==)