The RxJS operator map
can be used to map the stream value to a new value. However, if you want to map to a static value that does not depend on the stream value, you can use the mapTo
operator. This operator accepts the value directly and you don't need to create an additional function.
// Use `map` for dynamic values
stream$.pipe(map((user) => user.isAdmin));
// Use `mapTo` for static values
stream$.pipe(mapTo(true));
Note: the mapTo
operator has been deprecated in RxJS 7 and will be removed in RxJS 8. It's better to use map
with a function that returns the static value.