Skip to content

Instantly share code, notes, and snippets.

@nhphong
Created July 20, 2019 04:32
Show Gist options
  • Save nhphong/74116e577d334327617bdf4aa6b937ee to your computer and use it in GitHub Desktop.
Save nhphong/74116e577d334327617bdf4aa6b937ee 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 this.publish { sharedSrc ->
Observable.merge(
sharedSrc.debounce(timeout, unit, scheduler)
.filter { predicate(it) },
sharedSrc.filter { !predicate(it) }
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment