Consider the following sample:
I have a non completing rxjs Observable providing me with an array of numbers (e.g. of([1, 2, 3, 4, 5])
) and a custom filter function that returns an Observable boolean (also non completing) for each number (signifying whether the number should be included in the result or not).
My question: What is the best combination of operators to apply this filter?
Note: A solution using toArray
(like described in RxJs: Filter array with inner observable) won't work for me: The observables returned by my filter function never complete and for obvious reasons toArray
can only work with streams that do.
What I came up with so far is this monster using the scan
operator: https://stackblitz.com/edit/from-and-back-to-array?devtoolsheight=133&file=index.ts
I believe it works, but I can't help thinking that there must be an easier way to accomplish this. ???? Anyone have an idea?
complete()
internally. (For exampleinterval(100)
creates such an Observable for testing. – lentschi