zl程序教程

您现在的位置是:首页 >  其它

当前栏目

[RxJS] Remember previous value by using pairwise operator

by value Using Rxjs Operator previous
2023-09-14 09:00:47 时间

pairwise() will remember the last emit value.

 

const src = interval(1000)
  .pipe(
    pairwise(),
    scan((acc, [prev, curr]) => {
      console.log(prev, curr)
      return acc + curr;
    }, 0)
  ).subscribe() // 0 1