I have a problem with mergeScan, namely, I can't think of a single situation in which it'd be needed. The categories I see of problems _almost_ needing mergeScan are:
scan). The example in the docs is in this categorymergeMap). For instance, successive async calls.mergeScan falls flat on its face, as the accumulator passed in could be stale by the time the inner observable returns. In this case, it's better to just For example, see this (entirely contrived) example where I sum the weight of the first 10 Pok茅mon: http://jsbin.com/qosiwenaqi/edit?js,consoleIn short, I don't see a use for mergeScan that isn't better served by another operator and worse, it can cause unintended race conditions.
So, as a "What do we do about this issue", I'd like either:
mergeScan operator from RxJS v5or
mergeScan in the docs so silly folks don't open elaborate issues demanding its removal(Both @robwormald and @rgbkrk have discussed this with me in various Slacks so I'm cc'ing them here)
/cc'ing @trxcllnt too for visibility.
cc @trxcllnt ... this was his brain child back in the infancy of this lib.
Just for reference, here's the decision tree for it:
I have one existing Observable, and I want to compute a formula using all values emitted and output the computed values as a nested Observable when the source emits a value
output the computed values _as a nested Observable_
It's my understanding that the merge part of mergeScan unwraps the inner observable, only passing a value down the line?
mergeScan works like flatMap with an accumulated value. It isn't as commonly used as either flatMap or scan, but it isn't something that's easily accomplished by a combination of other operators, which is why it exists. There should also be a corresponding expandScan operator, but for various reasons I didn't get around to merging it in.
mergeScan works like flatMap with an accumulated value.
My query isn't about _how_ mergeScan works - I'm up to date on that. I want to know _when_ and _why_ I would use mergeScan. After several discussions, we couldn't come up with a single, practical example where one would use this operator.
It isn't as commonly used as either flatMap or scan
In fact, the first ten pages of GitHub results searching for mergeScan in both JS and TS show no actual uses of the operator (only people who've checked Rx into their repo).
various reasons I didn't get around to merging it in.
Pun intended? 馃槀
We can consider removing mergeScan for v6... It's a breaking change. However, by that version we should have treeshaking working, so I don't see the benefit to removing it other than to keep us from needing to maintain it... which has been zero maintenance so far.
Just so you know I'm using mergeScan to do progressive image display. I download and decode the image by chunk so I need the last chunk to compute the next and all this is done async using web worker.
But in fact I'm using concatScan because I set concurrent parameter to 1 that's why I'm not facing the race condition problem enounced.
On our project we are also using mergeScan. The simplified scenario is the following: There is a state, which is reflected on the UI, which can be modified by the user, but not directly, just with actions. There is a state-action pair which is sent to the server and it computes the next state and sends back.
We've just run into the race condition problem and it would be great if there would be an exhaustScan, but if my results are correct then this kind of operator doesn't exist.
There are certain paging scenarios where it makes sense as well, see: https://stackoverflow.com/questions/45383857/building-an-infinite-scrolling-list-in-typescript-with-rxjs5/45405933#45405933
Granted I still haven't found a use case for concurrency greater than 1, unless your data was order agnostic.
mergeScan solves an important scenario for me, where I have a sequence of async calls. Say, first call gets an user record from a DB, second call is to external service and passes user's attributes obtained from the first call, third call is to yet another service, and requires some data from first and the second calls. Passing an accumulator with intermediate results which mergeScan does makes this pretty straightforward.
I think we need better documentation sure... but we're not going to remove it for now. :)
@ladyleet, can you please have the docs folks take a look at documenting this one better?
for sure @benlesh!
Referenced here https://github.com/ReactiveX/rxjs-docs/issues/169
Please don't get rid of it very useful as a concatScan with concurrency = 1
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Just so you know I'm using
mergeScanto do progressive image display. I download and decode the image by chunk so I need the last chunk to compute the next and all this is done async using web worker.But in fact I'm using
concatScanbecause I set concurrent parameter to 1 that's why I'm not facing the race condition problem enounced.