Skip to content

Instantly share code, notes, and snippets.

@Shivamdhuria
Created November 29, 2020 19:51
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 Shivamdhuria/77183fd69c331e7d5a05e72ecebbbff4 to your computer and use it in GitHub Desktop.
Save Shivamdhuria/77183fd69c331e7d5a05e72ecebbbff4 to your computer and use it in GitHub Desktop.
private val _searchQuery = MutableStateFlow("")
fun setSearchQuery(query: String) {
_searchQuery.value = query
}
val networkOperationResult: Flow<String> = _searchQuery.debounce(1000).mapLatest {
if (it.isEmpty()) {
return@mapLatest ""
} else {
Log.e("Latest Mapped String Query", it)
return@mapLatest longNetworkOperation(it)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment