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

Fix Scan/Reduce/Collect Factory Ambiguity #1884

Merged

Conversation

benjchristensen
Copy link
Member

This puts the seed factory on collect and removes it from scan and reduce due to ambiguity.
See #1883 and #1881

The collect API was already very close so this fixes it to use a seed factory so the signature is now:

public final <R> Observable<R> collect(Func0<R> stateFactory, final Action2<R, ? super T> collector) {

I remove the factory overloads for scan and reduce due to the issue in #1881 related to generics, type erasure and lambdas causing ambiguity and compilation failures.

We may want to add at least a scan impl in the future with a seed factory, but it will need a different name if we do such as scanTo. I don't want to do that now for 1.0 so we'll need to revisit that for 1.1 with more time to think about it.

This puts the seed factory on `collect` and removes it from `scan` and `reduce` due to ambiguity.
See ReactiveX#1883 and ReactiveX#1881
@benjchristensen
Copy link
Member Author

This code is now possible:

        Observable.range(0, 10).collect(() -> new ArrayList<Integer>(), (list, i) -> {
            list.add(i);
        }).forEach(System.out::println);

This will no longer compile:

        Observable.range(0, 10).scan(() -> new ArrayList<Integer>(), (list, i) -> {
            list.add(i);
            return list;
        }).forEach(System.out::println);     

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

Successfully merging this pull request may close these issues.

1 participant