Мы можем выдать последнее значение после его изменения:
In: 1 - 1 - 1 - 2 - 2 - 3 - 3 - 1 - 1 - 1 - 2 - 2 - 2 - 1 - 2 - 2 - 3 - 3
Out: - - - - - - 1 - - - 2 - - - 3 - - - - - 1 - - - - - 2 - 1 - - - 2 - 3
import { pairwise, take, filter, map, merge, last } from 'rxjs/operators';
import { interval, from } from 'rxjs';
const stream$ = from([1, 1, 1, 2, 2, 3, 3, 1, 1, 1, 2, 2, 2, 1, 2, 2, 3, 3]);
stream$
.pipe(
pairwise(),
filter(([prev, cur]) => prev !== cur),
map(([prev, cur]) => prev),
merge(stream$.pipe(last()))
)
.subscribe(console.log);