DEV Community

Discussion on: RxJS - Simplifying Complex Operator Chains

Collapse
 
averyferrante profile image
Joseph Avery Ferrante • Edited

Very good point. In my examples I'm not naming the stream variable, but that is definitely also a good source for code clarity/self commenting code.

Also I agree that only having one function in the pipe chain is probably overkill, but really wanted to drive the point home.

To expand on this idea just a bit, you can still make a function more flexible in this case (multiplyBy10 is a bit rigid) by using a factory function:

function multiplyBy(amount: number) {
  return (numberFromStream: number) => amount * numberFromStream;
}

interval(500).pipe(
  map(multiplyBy(10))
)

Thanks for providing a bit of an alternative!