I have a stream of strings and I want to emit each line. Basically from this:
let stream$ = from(['hello\n', 'world ', ' at\nhome\n and', ' more'])
I want to emit this stream:
'hello'
'world at'
'home'
' and more'
My guess is that I need the merge operator after making sure there are no stream values with more than one line break. Something like:
let break$ = new Subject()
stream$.pipe(
flatMap(x => x.match(/[^\n]+\n?|\//g)),
map(x => {
if (x.endsWith('\n')) {
break$.next(true)
return x
}
return x
})
.buffer(break$)
)
However this pipe emits a single value, but I am sure the break$ really gets called when the stream of values should form a group. Currently this is the output:
[ 'hello\n', 'world ', ' at\n', 'home\n', ' and', ' more' ]
but my expectation was
[
['hello\n'],
['world ', ' at\n'],
['home\n'],
[' and', ' more'],
]
I do have a working solution, but that triggers a subscription and I would rather have a pipe for the lazy evaluation