Skip to content

Instantly share code, notes, and snippets.

@drawers
Created August 11, 2019 08:25
Show Gist options
  • Save drawers/09501f97c28868c753e2d0afc6cc0c4c to your computer and use it in GitHub Desktop.
Save drawers/09501f97c28868c753e2d0afc6cc0c4c to your computer and use it in GitHub Desktop.
Extension method on Observable
fun <T> Observable<T>.debounceIf(predicate: (T) -> Boolean, delay: Long, unit: TimeUnit): Observable<T> {
return this.debounce {
when {
predicate(it) -> Observable.timer(delay, unit)
else -> Observable.empty()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment