A clock stream may emit the same displayed time many times. A combinator transforms an observable into a new observable—for example, formatting dates or removing repeated values—without changing the original stream. section 33.2
currentTime$.map(data => `${date.getHours()}:${date.getMinutes()}`).distinct();
Map each date to a time string, then use distinct to suppress repeated strings. section 33.2
A custom combinator takes an observable and a function, subscribes to the existing stream, and returns a new observable. It can forward only values that pass a test. A complete version would also forward errors and completion. section 33.3 section 33.4
function filter (obs$, fn) { 1
return new Observable(observer => obs$.subscribe({ 2
next(val) {
if (fn(val)) observer.next(val); 3
}
}));
}
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":59},{\"line\":0,\"ch\":60}],[{\"line\":1,\"ch\":59},{\"line\":1,\"ch\":60}],[{\"line\":3,\"ch\":59},{\"line\":3,\"ch\":60}]]"}
!@%STYLE%@!
This filter combinator subscribes to an existing observable and forwards a value only when the supplied function accepts it. section 33.3
Filter a number stream
Applying the filter combinator to 1, 2, 3, 4, and 5 with an odd-number test produces a new stream containing 1, 3, and 5. section 33.3



