孤独プログラマー譚

孤独死が近い。

RxJS オペレータscan, reduceの違い

scanはストリームごとにnextを発火する。

of(1, 2, 3, 4).pipe(
  scan((acc, val) => acc + val, 10)
)
.subscribe(cl) // 11, 13, 16, 20


reduceは、最後のストリームだけ、nextを発火する。

of(1, 2, 3, 4).pipe(
  reduce((acc, val) => acc + val, 100)
)
.subscribe(cl) // 120