Skip to content

Commit bbaf1bc

Browse files
author
jmhofer
committed
also adapted type signatures of the reduce methods
1 parent 12c73c7 commit bbaf1bc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,8 @@ public T call(T t1, T t2) {
17461746
*
17471747
* @param <T>
17481748
* the type item emitted by the source Observable
1749+
* @param <R>
1750+
* the type returned for each item of the target observable
17491751
* @param sequence
17501752
* the source Observable
17511753
* @param initialValue
@@ -1760,7 +1762,7 @@ public T call(T t1, T t2) {
17601762
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
17611763
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
17621764
*/
1763-
public static <T> Observable<T> reduce(Observable<T> sequence, T initialValue, Func2<T, T, T> accumulator) {
1765+
public static <T, R> Observable<R> reduce(Observable<T> sequence, R initialValue, Func2<R, T, R> accumulator) {
17641766
return takeLast(create(OperationScan.scan(sequence, initialValue, accumulator)), 1);
17651767
}
17661768

@@ -1778,6 +1780,8 @@ public static <T> Observable<T> reduce(Observable<T> sequence, T initialValue, F
17781780
*
17791781
* @param <T>
17801782
* the type item emitted by the source Observable
1783+
* @param <R>
1784+
* the type returned for each item of the target observable
17811785
* @param sequence
17821786
* the source Observable
17831787
* @param initialValue
@@ -1791,17 +1795,15 @@ public static <T> Observable<T> reduce(Observable<T> sequence, T initialValue, F
17911795
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
17921796
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
17931797
*/
1794-
public static <T> Observable<T> reduce(final Observable<T> sequence, final T initialValue, final Object accumulator) {
1798+
public static <T, R> Observable<R> reduce(final Observable<T> sequence, final R initialValue, final Object accumulator) {
17951799
@SuppressWarnings("rawtypes")
17961800
final FuncN _f = Functions.from(accumulator);
1797-
return reduce(sequence, initialValue, new Func2<T, T, T>() {
1798-
1801+
return reduce(sequence, initialValue, new Func2<R, T, R>() {
17991802
@SuppressWarnings("unchecked")
18001803
@Override
1801-
public T call(T t1, T t2) {
1802-
return (T) _f.call(t1, t2);
1804+
public R call(R r, T t) {
1805+
return (R) _f.call(r, t);
18031806
}
1804-
18051807
});
18061808
}
18071809

0 commit comments

Comments
 (0)