如何使用RxJava2将多个单词组合成一个句子?

时间:2018-08-13 15:31:11

标签: java stream rx-java reactive-programming rx-java2

基本上,我有一连串的单词Observable<String>

我想要的是累积它们,直到我有一个“。”之前什么都没有发出。 当我有一个“。”我想宣读整个句子。以此类推,直到流完成。

1) The -> nothing, accumulated
2) quick -> nothing, accumulated
3) brown -> nothing, accumulated
4) fox -> nothing, accumulated
5) jumps -> nothing, accumulated
6) over -> nothing, accumulated
7) the -> nothing, accumulated
8) lazy -> nothing, accumulated
9) dog. -> emit the whole sentence, clear accumulator

扫描,缩小-看上去相似,但不完全相同,不确定

1 个答案:

答案 0 :(得分:1)

有扩展操作符bufferUntil,您可以使用collect直到字符串包含标点,然后将字符串列表合并为一个字符串:

Stream