Selector

typealias Selector<State, SubState> = suspend (State) -> SubState(source)

Inspirited by NgRx memoized selector.

Selectors are pure functions used for obtaining slices of a Flow of state. FlowExt provides a few helper functions for optimizing this selection.

  • Selectors can compute derived data, to store the minimal possible state.

  • Selectors are efficient. A selector is not recomputed unless one of its arguments changes.

  • When using the select functions, it will keep track of the latest arguments in which your selector function was invoked. Because selectors are pure functions, the last result can be returned when the arguments match without re-invoking your selector function. This can provide performance benefits, particularly with selectors that perform expensive computation. This practice is known as memoization.