Splitting the data of one observable into multiple observables


In a recent thread on the matrix, we thought about the question, how to split data transported over a reactive flow into multiple events, depending on data size.
several solutions where proposed. splitting the data according to a given size can be done using the GroupBy (Length) node from the Spread category, in combination with an Add (Spread) node, which appends the remainder of the split to the Spread. The resulting is a Spread of Spreads, where each element will be transformed to an individual Observable event. Several equally working strategies were supposed:

the simplest solution (in node count) proposed by @woei appears to be a combination of Select (Many) and a ToObservable node (from the System.Reactive.Observable category, which has to be manually referenced):

@woei writes:
SelectMany + toObservable<IEnumerable>
where the to observable is directly imported instead of the forwarded node. sure, there is a reason why it’s not exposed directly, but i don’t know/remember why. was something about the observable source switching while patching if i remember correctly

a similar solution using the available ToObservable (Sequence) node from CoreLib does not work in combination with Select (many):

other working solutions were suggested by @tobyk, @sebl and myself:
here a combination of ForEach (Reactive) ToObservable(Sequence) and Switch (Reactive) does give the expected result.

Building an Observable Sequence using a standard ForEach with Start [Reactive.Observable] inside and Merge [Reactive.Observable] works as well.

Using Channels it is possible to get a similar result:

Big thanks to @tobyk , @sebl and @woei for the insights!
ReactiveOnSpreadIdea_v3.vl (76.9 KB)


This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.