-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate partition, add splitBy method that multicasts the source sequence #3807
Comments
Seconded. To my mind, the partition operator is not fully useful yet: There needs to be another one that does not subscribe twice. For trivial examples like in the docs, it works totally fine. Behind the scenes however, it subscribes to the observable behind partition twice which might double the work the code does. In my concrete case, I followed the docs to split success and error cases. However, instead of calculating if a number is odd or even, I did an API call (with flatMap / catchError in case anything goes wrong). In my opinion, this is quite a common use case. If you now partition this by success / failure and subscribe to both partitioned streams, the API call is actually performed twice because there are two subscriptions that are merged back into one. This might be undesirable because it could double the load on the server (if there is no caching in place). For this scenario, I might be missing a better operator. In this case, I am sorry. However, the splitBy that is described here seems like a perfect match for the situation I'm facing. As a workaround, i am using a custom operator that uses two subjects and passes elements on correctly, but I doubt this is production-ready yet. |
FWIW, I implemented this, but never got around to discussing it or opening a PR: https://github.com/cartant/rxjs-etc/blob/master/source/operators/splitBy.ts |
That looks very promising, thanks. Maybe it would be a good idea to merge it back 😄 |
Would be good to get splitBy into rxjs. |
Core Team Meeting: Have @cartant move this into core, whenever he gets the chance. It seems like there's a good deal of interest. |
Okay, after a PR and some careful deliberation, we decided we aren't going to pursue getting this into core right now. For reasons that are outlined here: #6388 (comment) |
Related to #3797, the ideal replacement would be a method that mutlicasts the source sequence and returns two Observable "lanes", and sends values down one or the other lane based on the predicate. This is conceptually similar to
groupBy
with only two groups, except it returns an Array of the grouped Observables instead of an Observable of the groups since the groups can be known ahead of time.The text was updated successfully, but these errors were encountered: