Skip to content

Instantly share code, notes, and snippets.

@nhphong
Created July 8, 2019 03:21
Show Gist options
  • Save nhphong/d293089d015c7a611e4d71961a3280a7 to your computer and use it in GitHub Desktop.
Save nhphong/d293089d015c7a611e4d71961a3280a7 to your computer and use it in GitHub Desktop.
fun <T> Observable<T>.debounceIf(
predicate: (T) -> Boolean,
timeout: Long,
unit: TimeUnit,
scheduler: Scheduler
): Observable<T> {
return Observable.merge(
filter { predicate(it) }
.debounce(timeout, unit, scheduler),
filter { !predicate(it) }
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment