Skip to content

Commit ce9c6b5

Browse files
author
jmhofer
committed
Also added aggregate (alias for reduce, see issue ReactiveX#20).
1 parent bbaf1bc commit ce9c6b5

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,6 +3220,13 @@ public Observable<T> reduce(Func2<T, T, T> accumulator) {
32203220
return reduce(this, accumulator);
32213221
}
32223222

3223+
/**
3224+
* @see #reduce(Func2)
3225+
*/
3226+
public Observable<T> aggregate(Func2<T, T, T> accumulator) {
3227+
return reduce(accumulator);
3228+
}
3229+
32233230
/**
32243231
* Returns an Observable that applies a function of your choosing to the first item emitted by a
32253232
* source Observable, then feeds the result of that function along with the second item emitted
@@ -3246,6 +3253,13 @@ public Observable<T> reduce(Object accumulator) {
32463253
return reduce(this, accumulator);
32473254
}
32483255

3256+
/**
3257+
* @see #reduce(Object)
3258+
*/
3259+
public Observable<T> aggregate(Object accumulator) {
3260+
return reduce(accumulator);
3261+
}
3262+
32493263
/**
32503264
* Returns an Observable that applies a function of your choosing to the first item emitted by a
32513265
* source Observable, then feeds the result of that function along with the second item emitted
@@ -3270,10 +3284,17 @@ public Observable<T> reduce(Object accumulator) {
32703284
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
32713285
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
32723286
*/
3273-
public Observable<T> reduce(T initialValue, Func2<T, T, T> accumulator) {
3287+
public <R> Observable<R> reduce(R initialValue, Func2<R, T, R> accumulator) {
32743288
return reduce(this, initialValue, accumulator);
32753289
}
32763290

3291+
/**
3292+
* @see #reduce(R, Func2)
3293+
*/
3294+
public <R> Observable<R> aggregate(R initialValue, Func2<R, T, R> accumulator) {
3295+
return reduce(initialValue, accumulator);
3296+
}
3297+
32773298
/**
32783299
* Returns an Observable that applies a function of your choosing to the first item emitted by a
32793300
* source Observable, then feeds the result of that function along with the second item emitted
@@ -3297,10 +3318,17 @@ public Observable<T> reduce(T initialValue, Func2<T, T, T> accumulator) {
32973318
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
32983319
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
32993320
*/
3300-
public Observable<T> reduce(T initialValue, Object accumulator) {
3321+
public <R> Observable<R> reduce(R initialValue, Object accumulator) {
33013322
return reduce(this, initialValue, accumulator);
33023323
}
33033324

3325+
/**
3326+
* @see #reduce(R, Object)
3327+
*/
3328+
public <R> Observable<R> aggregate(R initialValue, Object accumulator) {
3329+
return reduce(initialValue, accumulator);
3330+
}
3331+
33043332
/**
33053333
* Returns an Observable that applies a function of your choosing to the first item emitted by a
33063334
* source Observable, then feeds the result of that function along with the second item emitted

0 commit comments

Comments
 (0)