Skip to content
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

Observable.scan() overload to take a factory for initial value? #3667

Closed
NiteshKant opened this issue Feb 4, 2016 · 7 comments
Closed

Observable.scan() overload to take a factory for initial value? #3667

NiteshKant opened this issue Feb 4, 2016 · 7 comments

Comments

@NiteshKant
Copy link
Member

Currently the scan operator has an overload to take an initial value for the accumulation. The problem with this is that the initial value is the same for all subscribers of this observable, which hardly is intended by the user. It is actually a source of subtle bugs for a casual user.

I think there should atleast be an overload that instead of the realized initial value takes a factory for the initial value for each subscription. The underlying OperatorScan already supports an initial value factory.

I would also suggest to either deprecate the current scan() method or if it is usable in some cases, atleast put a warning in the javadoc.

@zsxwing
Copy link
Member

zsxwing commented Feb 4, 2016

It was there but removed. See #1881 for the type erase issue and #1884 for collect.

@NiteshKant
Copy link
Member Author

Thanks @zsxwing. But collect and scan have different behaviors, isn't?
So, the question here still makes sense?

@NiteshKant
Copy link
Member Author

If there is some agreement on what to do here, I can send a PR.

@zsxwing
Copy link
Member

zsxwing commented Feb 4, 2016

Technically, you can implement scan(Func0, accumulator) using collect. I tried in RxScala but the code looks ugly, so I'm very happy to add a scan overload. However, we need a new method name due to the ambiguity. Any suggestion for the new method name?

@akarnokd
Copy link
Member

PRs are always welcome and sometimes the only means to get people moving around here.

@akarnokd
Copy link
Member

See #3959.

@akarnokd
Copy link
Member

Due to potential problems with the two parameter variant proposed in #3959, I added some javadoc instead showing how one can use defer to avoid sharing the mutable initial value (#4063).

If you have further input on the issue, don't hesitate to reopen this issue or post a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants