Skip to content

Instantly share code, notes, and snippets.

@ywett02
Last active January 23, 2019 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ywett02/de913d4ede0ccfa010194c4ee6206a12 to your computer and use it in GitHub Desktop.
Save ywett02/de913d4ede0ccfa010194c4ee6206a12 to your computer and use it in GitHub Desktop.
val reducer = BiFunction { previousState: CountryListViewState, result: CountryListResult ->
when (result) {
is LoadCountriesResult ->
when (result) {
is LoadCountriesResult.Success -> {
previousState.copy(
isLoading = false,
isRefreshing = false,
countries = result.countries
)
}
is LoadCountriesResult.Failure -> {
previousState.copy(
isLoading = false,
error = result.error
)
}
is LoadCountriesResult.InProgress -> {
if (result.isRefreshing) {
previousState.copy(
isLoading = false,
isRefreshing = true
)
} else previousState.copy(
isLoading = true,
isRefreshing = false
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment