RxJS takeWhile but include the last value

后端 未结 6 918
情书的邮戳
情书的邮戳 2020-12-06 04:16

I have a RxJS5 pipeline looks like this

Rx.Observable.from([2, 3, 4, 5, 6])
  .takeWhile((v) => { v !== 4 })

I want to keep the subscrip

6条回答
  •  温柔的废话
    2020-12-06 04:50

    If your comparison is such that you know exactly what is the last element (like for !==), you can re-add it yourself:

    Rx.Observable.from([2, 3, 4, 5, 6])
      .takeWhile((v) => v !== 4)
      .concat(Rx.Observable.of(4))
      .subscribe(console.log)
    

提交回复
热议问题