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

reduce() with a mutable initial value #1831

Closed
tommack opened this issue Nov 6, 2014 · 3 comments
Closed

reduce() with a mutable initial value #1831

tommack opened this issue Nov 6, 2014 · 3 comments
Milestone

Comments

@tommack
Copy link

tommack commented Nov 6, 2014

In this example (https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#reduce)

getComingSoonSequence()
    .reduce([], { theList, video ->
                  theList.add("'" + video.getTitle() + "' (" + video.getOpen() + ")");
                  return(theList);
    }).subscribe({ println("Coming Soon: " + it) });

Passing a list into the reduce method seems like it would only be valid if you could guarantee that the Observable would only be subscribed to once. Why isn't there a reduce method that takes a Supplier as its first argument?

@benjchristensen
Copy link
Member

That is an excellent question and a major oversight. Same issue with scan.

@benjchristensen benjchristensen added this to the 1.0 milestone Nov 6, 2014
benjchristensen added a commit to benjchristensen/RxJava that referenced this issue Nov 8, 2014
Adds overload with seed factory as per ReactiveX#1831
@benjchristensen
Copy link
Member

Added overloads for scan and reduce that take a factory.

@benjchristensen
Copy link
Member

We had to revert these changes due to issues shown in #1883. It was done in #1884.

You can instead use collect for the mutable reduce use case which now uses a factory for the initial value.

We'll have to evaluate whether scan needs a new signature to support this and if so add it later in 1.1 with a new name such as scanTo since we can't overload the method due to generics, type erasure and lambdas colliding.

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

2 participants