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

Remove covariance of scan/reduce #369

Merged

Conversation

benjchristensen
Copy link
Member

Remove covariance of scan/reduce since consumer/producer are the same <T, T, T>

See #360 (comment)

@cloudbees-pull-request-builder

RxJava-pull-requests #263 SUCCESS
This pull request looks good

@abersnaze
Copy link
Contributor

This method and friends
public <R> Observable<R> reduce(R initialValue, Func2<? super R, ? super T, ? extends R> accumulator) {
also needs to changed to
public <R> Observable<R> reduce(R initialValue, Func2<R, ? super T, R> accumulator) {

T2 should remain "? super T" because it is only consumed.

@benjchristensen
Copy link
Member Author

I didn't change those yet as I wasn't sure if they behave differently because they consume and produce different types. I wasn't able to get an example that proved or disproved anything so left it until I can.

Do you have example code that shows that method doesn't benefit from ? super T?

And what T2 are you referring to? There isn't anything with a type T2 in reduce.

@abersnaze
Copy link
Contributor

Func2<T1, T2, R>

@benjchristensen
Copy link
Member Author

(George and I chatted in person)

We looked at JDK 8 to try and get a final representation of others doing this and it does it like this:

<U> U reduce(U identity,
             BiFunction<U,? super T,U> accumulator,
             BinaryOperator<U> combiner)

This is at: http://download.java.net/jdk8/docs/api/java/util/stream/Stream.html#reduce(U,%20java.util.function.BiFunction,%20java.util.function.BinaryOperator)

Optional<T> reduce(BinaryOperator<T> accumulator)

The BinaryOperator is this:

public interface BinaryOperator<T>
extends BiFunction<T,T,T>

Thus this seems to confirm the decision to remove ? super in reduce without a seed and in the one with a seed value do what George recommended:

reduce(R initialValue, Func2<R, ? super T, R> accumulator)

benjchristensen added a commit that referenced this pull request Sep 11, 2013
@benjchristensen benjchristensen merged commit e3d04e3 into ReactiveX:master Sep 11, 2013
@benjchristensen benjchristensen deleted the reduce-and-scan-covariance branch September 11, 2013 16:53
@cloudbees-pull-request-builder

RxJava-pull-requests #267 SUCCESS
This pull request looks good

rickbw pushed a commit to rickbw/RxJava that referenced this pull request Jan 9, 2014
rickbw pushed a commit to rickbw/RxJava that referenced this pull request Jan 9, 2014
…-covariance

Remove covariance of scan/reduce
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.

3 participants