Skip to content

Commit 3bba245

Browse files
Remove newly added aggregate methods
- avoiding methods with `index` - resultSelector overload is same as `reduce(seed, accumulator).map(resultSelector)`
1 parent 225eafa commit 3bba245

File tree

3 files changed

+5
-234
lines changed

3 files changed

+5
-234
lines changed

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

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5327,7 +5327,7 @@ public Observable<T> aggregate(Func2<T, T, T> accumulator) {
53275327
public <R> Observable<R> reduce(R initialValue, Func2<R, ? super T, R> accumulator) {
53285328
return create(OperationScan.scan(this, initialValue, accumulator)).takeLast(1);
53295329
}
5330-
5330+
53315331
/**
53325332
* Synonymous with <code>reduce()</code>.
53335333
* <p>
@@ -5341,49 +5341,6 @@ public <R> Observable<R> aggregate(R initialValue, Func2<R, ? super T, R> accumu
53415341
return reduce(initialValue, accumulator);
53425342
}
53435343

5344-
/**
5345-
* Create an Observable that aggregates the source values with the given accumulator
5346-
* function and projects the final result via the resultselector.
5347-
* <p>
5348-
* Works like the {@link #aggregate(java.lang.Object, rx.util.functions.Func2)} projected
5349-
* with {@link #map(rx.util.functions.Func1)} without the overhead of some helper
5350-
* operators.
5351-
* @param <U> the intermediate (accumulator) type
5352-
* @param <V> the result type
5353-
* @param seed the initial value of the accumulator
5354-
* @param accumulator the function that takes the current accumulator value,
5355-
* the current emitted value and returns a (new) accumulated value.
5356-
* @param resultSelector the selector to project the final value of the accumulator
5357-
* @return an Observable that aggregates the source values with the given accumulator
5358-
* function and projects the final result via the resultselector
5359-
*/
5360-
public <U, V> Observable<V> aggregate(
5361-
U seed, Func2<U, ? super T, U> accumulator,
5362-
Func1<? super U, ? extends V> resultSelector) {
5363-
return create(new OperationAggregate.AggregateSelector<T, U, V>(this, seed, accumulator, resultSelector));
5364-
}
5365-
5366-
/**
5367-
* Create an Observable that aggregates the source values with the given indexed accumulator
5368-
* function and projects the final result via the indexed resultselector.
5369-
*
5370-
* @param <U> the intermediate (accumulator) type
5371-
* @param <V> the result type
5372-
* @param seed the initial value of the accumulator
5373-
* @param accumulator the function that takes the current accumulator value,
5374-
* the current emitted value and returns a (new) accumulated value.
5375-
* @param resultSelector the selector to project the final value of the accumulator, where
5376-
* the second argument is the total number of elements accumulated
5377-
* @return an Observable that aggregates the source values with the given indexed accumulator
5378-
* function and projects the final result via the indexed resultselector.
5379-
*/
5380-
public <U, V> Observable<V> aggregateIndexed(
5381-
U seed, Func3<U, ? super T, ? super Integer, U> accumulator,
5382-
Func2<? super U, ? super Integer, ? extends V> resultSelector
5383-
) {
5384-
return create(new OperationAggregate.AggregateIndexedSelector<T, U, V>(this, seed, accumulator, resultSelector));
5385-
}
5386-
53875344
/**
53885345
* Returns an Observable that applies a function of your choosing to the
53895346
* first item emitted by a source Observable, then feeds the result of that

rxjava-core/src/main/java/rx/operators/OperationAggregate.java

Lines changed: 0 additions & 158 deletions
This file was deleted.

rxjava-core/src/test/java/rx/operators/OperationAggregateTest.java renamed to rxjava-core/src/test/java/rx/operators/OperationReduceTest.java

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,41 +45,13 @@ public Integer call(Integer t1, Integer t2) {
4545
@Test
4646
public void testAggregateAsIntSum() {
4747

48-
Observable<Integer> result = Observable.from(1, 2, 3, 4, 5).aggregate(0, sum, Functions.<Integer>identity());
48+
Observable<Integer> result = Observable.from(1, 2, 3, 4, 5).reduce(0, sum).map(Functions.<Integer>identity());
4949

5050
result.subscribe(observer);
5151

5252
verify(observer).onNext(1 + 2 + 3 + 4 + 5);
5353
verify(observer).onCompleted();
5454
verify(observer, never()).onError(any(Throwable.class));
55-
56-
}
57-
58-
@Test
59-
public void testAggregateIndexedAsAverage() {
60-
Func3<Integer, Integer, Integer, Integer> sumIndex = new Func3<Integer, Integer, Integer, Integer>() {
61-
@Override
62-
public Integer call(Integer acc, Integer value, Integer index) {
63-
return acc + (index + 1) + value;
64-
}
65-
};
66-
Func2<Integer, Integer, Integer> selectIndex = new Func2<Integer, Integer, Integer>() {
67-
@Override
68-
public Integer call(Integer t1, Integer count) {
69-
return t1 + count;
70-
}
71-
72-
};
73-
74-
Observable<Integer> result = Observable.from(1, 2, 3, 4, 5)
75-
.aggregateIndexed(0, sumIndex, selectIndex);
76-
77-
result.subscribe(observer);
78-
79-
verify(observer).onNext(2 + 4 + 6 + 8 + 10 + 5);
80-
verify(observer).onCompleted();
81-
verify(observer, never()).onError(any(Throwable.class));
82-
8355
}
8456

8557
static class CustomException extends RuntimeException { }
@@ -88,7 +60,7 @@ static class CustomException extends RuntimeException { }
8860
public void testAggregateAsIntSumSourceThrows() {
8961
Observable<Integer> result = Observable.concat(Observable.from(1, 2, 3, 4, 5),
9062
Observable.<Integer>error(new CustomException()))
91-
.aggregate(0, sum, Functions.<Integer>identity());
63+
.reduce(0, sum).map(Functions.<Integer>identity());
9264

9365
result.subscribe(observer);
9466

@@ -107,7 +79,7 @@ public Integer call(Integer t1, Integer t2) {
10779
};
10880

10981
Observable<Integer> result = Observable.from(1, 2, 3, 4, 5)
110-
.aggregate(0, sumErr, Functions.<Integer>identity());
82+
.reduce(0, sumErr).map(Functions.<Integer>identity());
11183

11284
result.subscribe(observer);
11385

@@ -128,7 +100,7 @@ public Integer call(Integer t1) {
128100
};
129101

130102
Observable<Integer> result = Observable.from(1, 2, 3, 4, 5)
131-
.aggregate(0, sum, error);
103+
.reduce(0, sum).map(error);
132104

133105
result.subscribe(observer);
134106

0 commit comments

Comments
 (0)