private fun localeSettingsStateReducer( state: LocaleSettingsState, action: LocaleSettingsAction, ): LocaleSettingsState { return when (action) { is LocaleSettingsAction.Select -> { state.copy(selectedLocale = action.selectedItem, searchedLocaleList = state.localeList) } is LocaleSettingsAction.Search -> { val searchedItems = state.localeList.filter { it.getDisplayLanguage(it).startsWith(action.query, ignoreCase = true) || it.displayLanguage.startsWith(action.query, ignoreCase = true) || it === state.localeList[0] } state.copy(searchedLocaleList = searchedItems) } } }
Reduces the locale state from the current state and an action performed on it.