Skip to content

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.

2 participants