/** * @license Use of this source code is governed by an MIT-style license that * can be found in the LICENSE file at https://github.com/cartant/rxjs-etc */ import { concat, MonoTypeOperatorFunction, ReplaySubject } from "rxjs"; import { filter, multicast, take, takeWhile } from "rxjs/operators"; export function takeWhileInclusive( predicate: (value: T) => boolean ): MonoTypeOperatorFunction { // https://stackoverflow.com/a/44644237/6680611 return (source) => source.pipe( multicast( () => new ReplaySubject(1), (sharedSource) => concat( sharedSource.pipe(takeWhile(predicate)), sharedSource.pipe( take(1), filter((value) => !predicate(value)) ) ) ) ); }