Skip to content

Instantly share code, notes, and snippets.

@cartant
Created August 18, 2017 07:38
Show Gist options
  • Save cartant/187a51a644eb148291c52e905fb2e112 to your computer and use it in GitHub Desktop.
Save cartant/187a51a644eb148291c52e905fb2e112 to your computer and use it in GitHub Desktop.
function takeWhileInclusive<T>(
predicate: (value: T) => boolean
): (source: Observable<T>) => Observable<T> {
return source => source.multicast(
() => new ReplaySubject<T>(1),
shared => shared
.takeWhile(predicate)
.concat(shared.take(1).filter(t => !predicate(t)))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment