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 Lambda Ambiguity #1883

Closed

Conversation

benjchristensen
Copy link
Member

This fixes the Java 8 lambda ambiguity between the overloads: #1881

This is a breaking change for anyone using scan, reduce, collect with an initial value.

There are two approaches to adapting.

If the initial value is the same type such as this:

stream.scan(1, Func2<Integer, Integer, Integer>)

then you can use startWith:

stream.startWith(1).scan(Func2<Integer, Integer, Integer>)

If it is a different type then a seed factory is needed:

stream.scan(Func0<List>, Func2< List, Integer, List >)

In Java 8 this would change from this:

stream.scan(new ArrayList(), (list, item) -> {
    list.add(item);
    return list;
});

to this:

stream.scan(() -> new ArrayList(), (list, item) -> {
    list.add(item);
    return list;
});

The same change happens in reduce and collect.

This fixes the Java 8 ambiguity between the overloads: ReactiveX#1881
@benjchristensen
Copy link
Member Author

cc @headinthebox for a review of this. This is cutting it close for 1.0 release but an important fix. Thanks @tommack for bringing this problem to our attention in #1831.

@benjchristensen
Copy link
Member Author

Pulling the factory overloads from 1.0. Will take time to get right in 1.1.

@headinthebox
Copy link
Contributor

@davgross can you update the docs to emphasize that mutable state is evil when doing aggregation?

benjchristensen added a commit to benjchristensen/RxJava that referenced this pull request Nov 15, 2014
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

Fixed in #1884

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.

None yet

2 participants