There is in RxJS6 (no clue when it was added to be honest)
Documentation:
https://rxjs-dev.firebaseapp.com/api/operators/endWith
Source: https://github.com/ReactiveX/rxjs/blob/df0ea7c78767c07a6ed839608af5a7bb4cefbde5/src/internal/operators/endWith.ts
Also, defaultIfEmpty()
only emits a value if the observable CLOSES without emitting a value. It's a subtle, yet not so subtle distinction. It may have the same effect as endWith()
in limited situations.
Example of endWith():
const source = of(1, 2, 3, 4, 5);
const example = source.pipe(
takeWhile(val => val != 4),
endWith(4));
Emits:
[1, 2, 3, 4]
Also I'm noticing that the https://learnrxjs.io website is increasingly out of date, and currently doesn't show this operator.
Why did I need it?
I was looking for the ability to emit false
until a condition became true
, but never go back to false. So slightly similar to debouncing, but not quite.