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

Improved scan, reduce, aggregate #257

Merged
merged 8 commits into from
May 7, 2013

Conversation

jmhofer
Copy link
Contributor

@jmhofer jmhofer commented May 4, 2013

scan is currently restricted to accumulators of type Func2<T, T, T> where Func2<R, T, R> would be possible for initial values of type R. This pull request tries to fix this by generalizing the scan implementation. I had to restructure the scan operator a bit for this to stay typesafe. Imho it's more readable now, though.

This indirectly leads to generalized reduce, too.

Also, aggregate is added as an alias for reduce (see #20).

@cloudbees-pull-request-builder

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

@cloudbees-pull-request-builder

RxJava-pull-requests #121 FAILURE
Looks like there's a problem with this pull request

@cloudbees-pull-request-builder

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

@benjchristensen
Copy link
Member

Thank you for working on this.

  • Observable had not had any changes done to it to expose the new reduce or scan methods so that should probably be added to this pull request.
  • What names should we use on the public API?

Rx.Net never used reduce, it uses aggregate. Others call it fold, accumulate etc (more here http://en.wikipedia.org/wiki/Fold_(higher-order_function))

Java 8 is using the reduce and collector names (http://download.java.net/lambda/b74/docs/api/java/util/stream/Stream.html)

What names should we use and what aliases if any should we include in Observable?

@jmhofer
Copy link
Contributor Author

jmhofer commented May 6, 2013

About Observable - hmm, seems that the changes got lost somehow... I'll go dig them out again.

And about the names to use: imho RxJava should have the Java 8 names as well as the orginial Rx.Net names.

@benjchristensen
Copy link
Member

Agreed with your opinion on naming. Can you add those when you update the Observable and make sure the Javadocs of the methods are clear in linking to each other when they are aliases of each other?

@jmhofer
Copy link
Contributor Author

jmhofer commented May 7, 2013

I've had a look at the Java 8 stream operations. To me, it looks like there's no explicit scan equivalent in Java 8. Or am I missing something?

collect seems to be specifically made for mutable operations. I don't see where we would use that.

So, I would just alias reduce with aggregate, and scan stays unaliased, if that's okay.

@benjchristensen
Copy link
Member

That works for me, we can always add more aliases if Java 8 adds a scan equivalent.

@benjchristensen
Copy link
Member

I plan on doing a release tomorrow (about 12 hours from now) if you want to try and have this ready for that.

@cloudbees-pull-request-builder

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

@jmhofer
Copy link
Contributor Author

jmhofer commented May 7, 2013

As soon as this is in, my swing branch becomes finally ready for a merge. It offers a few simple observables created from button click, keyboard and mouse events. Looking forward to this. :)

benjchristensen added a commit that referenced this pull request May 7, 2013
Improved scan, reduce, aggregate
@benjchristensen benjchristensen merged commit fd78b7c into ReactiveX:master May 7, 2013
@jmhofer jmhofer deleted the improved-scan branch May 7, 2013 14:06
rickbw pushed a commit to rickbw/RxJava that referenced this pull request Jan 9, 2014
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