Skip to content

Commit b20b62c

Browse files
author
jmhofer
committed
fixed method signatures and respective javadocs of various aggregate/reduce/scan overloads
1 parent 27f72d4 commit b20b62c

File tree

1 file changed

+71
-175
lines changed

1 file changed

+71
-175
lines changed

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

Lines changed: 71 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,30 +1696,9 @@ public static <T> Observable<T> reduce(Observable<T> sequence, Func2<T, T, T> ac
16961696
}
16971697

16981698
/**
1699-
* Returns an Observable that applies a function of your choosing to the first item emitted by a
1700-
* source Observable, then feeds the result of that function along with the second item emitted
1701-
* by an Observable into the same function, and so on until all items have been emitted by the
1702-
* source Observable, emitting the final result from the final call to your function as its sole
1703-
* output.
1704-
* <p>
1705-
* This technique, which is called "reduce" here, is sometimes called "fold," "accumulate," "compress," or "inject" in other programming contexts. Groovy, for instance, has an <code>inject</code>
1706-
* method that does a similar operation on lists.
1707-
* <p>
1708-
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/reduce.png">
1699+
* Used by dynamic languages.
17091700
*
1710-
* @param <T>
1711-
* the type item emitted by the source Observable
1712-
* @param sequence
1713-
* the source Observable
1714-
* @param accumulator
1715-
* an accumulator function to be invoked on each element from the sequence, whose
1716-
* result will be used in the next accumulator call (if applicable)
1717-
*
1718-
* @return an Observable that emits a single element that is the result of accumulating the
1719-
* output from applying the accumulator to the sequence of items emitted by the source
1720-
* Observable
1721-
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
1722-
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
1701+
* @see #reduce(Observable, Func2)
17231702
*/
17241703
public static <T> Observable<T> reduce(final Observable<T> sequence, final Object accumulator) {
17251704
@SuppressWarnings("rawtypes")
@@ -1735,6 +1714,22 @@ public T call(T t1, T t2) {
17351714
});
17361715
}
17371716

1717+
/**
1718+
* @see #reduce(Observable, Func2)
1719+
*/
1720+
public static <T> Observable<T> aggregate(Observable<T> sequence, Func2<T, T, T> accumulator) {
1721+
return reduce(sequence, accumulator);
1722+
}
1723+
1724+
/**
1725+
* Used by dynamic languages.
1726+
*
1727+
* @see #reduce(Observable, Func2)
1728+
*/
1729+
public static <T> Observable<T> aggregate(Observable<T> sequence, Object accumulator) {
1730+
return reduce(sequence, accumulator);
1731+
}
1732+
17381733
/**
17391734
* Returns an Observable that applies a function of your choosing to the first item emitted by a
17401735
* source Observable, then feeds the result of that function along with the second item emitted
@@ -1770,33 +1765,9 @@ public static <T, R> Observable<R> reduce(Observable<T> sequence, R initialValue
17701765
}
17711766

17721767
/**
1773-
* Returns an Observable that applies a function of your choosing to the first item emitted by a
1774-
* source Observable, then feeds the result of that function along with the second item emitted
1775-
* by an Observable into the same function, and so on until all items have been emitted by the
1776-
* source Observable, emitting the final result from the final call to your function as its sole
1777-
* output.
1778-
* <p>
1779-
* This technique, which is called "reduce" here, is sometimes called "fold," "accumulate," "compress," or "inject" in other programming contexts. Groovy, for instance, has an <code>inject</code>
1780-
* method that does a similar operation on lists.
1781-
* <p>
1782-
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/reduce.png">
1768+
* Used by dynamic languages.
17831769
*
1784-
* @param <T>
1785-
* the type item emitted by the source Observable
1786-
* @param <R>
1787-
* the type returned for each item of the target observable
1788-
* @param sequence
1789-
* the source Observable
1790-
* @param initialValue
1791-
* a seed passed into the first execution of the accumulator function
1792-
* @param accumulator
1793-
* an accumulator function to be invoked on each element from the sequence, whose
1794-
* result will be used in the next accumulator call (if applicable)
1795-
* @return an Observable that emits a single element that is the result of accumulating the
1796-
* output from applying the accumulator to the sequence of items emitted by the source
1797-
* Observable
1798-
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
1799-
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
1770+
* @see #reduce(Observable, Object, Func2)
18001771
*/
18011772
public static <T, R> Observable<R> reduce(final Observable<T> sequence, final R initialValue, final Object accumulator) {
18021773
@SuppressWarnings("rawtypes")
@@ -1810,6 +1781,22 @@ public R call(R r, T t) {
18101781
});
18111782
}
18121783

1784+
/**
1785+
* @see #reduce(Observable, Object, Func2)
1786+
*/
1787+
public static <T, R> Observable<R> aggregate(Observable<T> sequence, R initialValue, Func2<R, T, R> accumulator) {
1788+
return reduce(sequence, initialValue, accumulator);
1789+
}
1790+
1791+
/**
1792+
* Used by dynamic languages.
1793+
*
1794+
* @see #reduce(Observable, Object, Func2)
1795+
*/
1796+
public static <T, R> Observable<R> aggregate(Observable<T> sequence, R initialValue, Object accumulator) {
1797+
return reduce(sequence, initialValue, accumulator);
1798+
}
1799+
18131800
/**
18141801
* Returns an Observable that applies a function of your choosing to the first item emitted by a
18151802
* source Observable, then feeds the result of that function along with the second item emitted
@@ -1834,23 +1821,9 @@ public static <T> Observable<T> scan(Observable<T> sequence, Func2<T, T, T> accu
18341821
}
18351822

18361823
/**
1837-
* Returns an Observable that applies a function of your choosing to the first item emitted by a
1838-
* source Observable, then feeds the result of that function along with the second item emitted
1839-
* by an Observable into the same function, and so on until all items have been emitted by the
1840-
* source Observable, emitting the result of each of these iterations as its own sequence.
1841-
* <p>
1842-
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/scan.png">
1824+
* Used by dynamic languages.
18431825
*
1844-
* @param <T>
1845-
* the type item emitted by the source Observable
1846-
* @param sequence
1847-
* the source Observable
1848-
* @param accumulator
1849-
* an accumulator function to be invoked on each element from the sequence, whose
1850-
* result will be emitted and used in the next accumulator call (if applicable)
1851-
* @return an Observable that emits a sequence of items that are the result of accumulating the
1852-
* output from the sequence emitted by the source Observable
1853-
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211665(v%3Dvs.103).aspx">MSDN: Observable.Scan</a>
1826+
* @see #scan(Observable, Func2)
18541827
*/
18551828
public static <T> Observable<T> scan(final Observable<T> sequence, final Object accumulator) {
18561829
@SuppressWarnings("rawtypes")
@@ -1894,27 +1867,9 @@ public static <T, R> Observable<R> scan(Observable<T> sequence, R initialValue,
18941867
}
18951868

18961869
/**
1897-
* Returns an Observable that applies a function of your choosing to the first item emitted by a
1898-
* source Observable, then feeds the result of that function along with the second item emitted
1899-
* by an Observable into the same function, and so on until all items have been emitted by the
1900-
* source Observable, emitting the result of each of these iterations as its own sequence.
1901-
* <p>
1902-
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/scan.png">
1870+
* Used by dynamic languages.
19031871
*
1904-
* @param <T>
1905-
* the type item emitted by the source Observable
1906-
* @param <R>
1907-
* the type returned for each item of the target observable
1908-
* @param sequence
1909-
* the source Observable
1910-
* @param initialValue
1911-
* the initial (seed) accumulator value
1912-
* @param accumulator
1913-
* an accumulator function to be invoked on each element from the sequence, whose
1914-
* result will be emitted and used in the next accumulator call (if applicable)
1915-
* @return an Observable that emits a sequence of items that are the result of accumulating the
1916-
* output from the sequence emitted by the source Observable
1917-
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211665(v%3Dvs.103).aspx">MSDN: Observable.Scan</a>
1872+
* @see #scan(Observable, Object, Func2)
19181873
*/
19191874
public static <T, R> Observable<R> scan(final Observable<T> sequence, final R initialValue, final Object accumulator) {
19201875
@SuppressWarnings("rawtypes")
@@ -3232,43 +3187,28 @@ public Observable<T> reduce(Func2<T, T, T> accumulator) {
32323187
}
32333188

32343189
/**
3235-
* @see #reduce(Func2)
3236-
*/
3237-
public Observable<T> aggregate(Func2<T, T, T> accumulator) {
3238-
return reduce(accumulator);
3239-
}
3240-
3241-
/**
3242-
* Returns an Observable that applies a function of your choosing to the first item emitted by a
3243-
* source Observable, then feeds the result of that function along with the second item emitted
3244-
* by an Observable into the same function, and so on until all items have been emitted by the
3245-
* source Observable, emitting the final result from the final call to your function as its sole
3246-
* output.
3247-
* <p>
3248-
* This technique, which is called "reduce" here, is sometimes called "fold," "accumulate,"
3249-
* "compress," or "inject" in other programming contexts. Groovy, for instance, has an
3250-
* <code>inject</code> method that does a similar operation on lists.
3251-
* <p>
3252-
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/reduce.png">
3190+
* Used by dynamic languages.
32533191
*
3254-
* @param accumulator
3255-
* An accumulator function to be invoked on each element from the sequence, whose result
3256-
* will be used in the next accumulator call (if applicable).
3257-
*
3258-
* @return an Observable that emits a single element from the result of accumulating the output
3259-
* from the list of Observables.
3260-
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
3261-
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
3192+
* @see #reduce(Func2)
32623193
*/
32633194
public Observable<T> reduce(Object accumulator) {
32643195
return reduce(this, accumulator);
32653196
}
32663197

32673198
/**
3268-
* @see #reduce(Object)
3199+
* @see #reduce(Func2)
3200+
*/
3201+
public Observable<T> aggregate(Func2<T, T, T> accumulator) {
3202+
return aggregate(this, accumulator);
3203+
}
3204+
3205+
/**
3206+
* Used by dynamic languages.
3207+
*
3208+
* @see #reduce(Func2)
32693209
*/
32703210
public Observable<T> aggregate(Object accumulator) {
3271-
return reduce(accumulator);
3211+
return aggregate(this, accumulator);
32723212
}
32733213

32743214
/**
@@ -3300,44 +3240,28 @@ public <R> Observable<R> reduce(R initialValue, Func2<R, T, R> accumulator) {
33003240
}
33013241

33023242
/**
3303-
* @see #reduce(R, Func2)
3243+
* Used by dynamic languages.
3244+
*
3245+
* @see #reduce(Object, Func2)
33043246
*/
3305-
public <R> Observable<R> aggregate(R initialValue, Func2<R, T, R> accumulator) {
3306-
return reduce(initialValue, accumulator);
3247+
public <R> Observable<R> reduce(R initialValue, Object accumulator) {
3248+
return reduce(this, initialValue, accumulator);
33073249
}
33083250

33093251
/**
3310-
* Returns an Observable that applies a function of your choosing to the first item emitted by a
3311-
* source Observable, then feeds the result of that function along with the second item emitted
3312-
* by an Observable into the same function, and so on until all items have been emitted by the
3313-
* source Observable, emitting the final result from the final call to your function as its sole
3314-
* output.
3315-
* <p>
3316-
* This technique, which is called "reduce" here, is sometimes called "fold," "accumulate,"
3317-
* "compress," or "inject" in other programming contexts. Groovy, for instance, has an
3318-
* <code>inject</code> method that does a similar operation on lists.
3319-
* <p>
3320-
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/reduce.png">
3321-
*
3322-
* @param initialValue
3323-
* The initial (seed) accumulator value.
3324-
* @param accumulator
3325-
* An accumulator function to be invoked on each element from the sequence, whose
3326-
* result will be used in the next accumulator call (if applicable).
3327-
* @return an Observable that emits a single element from the result of accumulating the output
3328-
* from the list of Observables.
3329-
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
3330-
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
3252+
* @see #reduce(Object, Func2)
33313253
*/
3332-
public <R> Observable<R> reduce(R initialValue, Object accumulator) {
3333-
return reduce(this, initialValue, accumulator);
3254+
public <R> Observable<R> aggregate(R initialValue, Func2<R, T, R> accumulator) {
3255+
return aggregate(this, initialValue, accumulator);
33343256
}
33353257

33363258
/**
3337-
* @see #reduce(R, Object)
3259+
* Used by dynamic languages.
3260+
*
3261+
* @see #reduce(Object, Func2)
33383262
*/
33393263
public <R> Observable<R> aggregate(R initialValue, Object accumulator) {
3340-
return reduce(initialValue, accumulator);
3264+
return aggregate(this, initialValue, accumulator);
33413265
}
33423266

33433267
/**
@@ -3391,23 +3315,9 @@ public Observable<T> sample(long period, TimeUnit unit, Scheduler scheduler) {
33913315
}
33923316

33933317
/**
3394-
* Returns an Observable that applies a function of your choosing to the first item emitted by a
3395-
* source Observable, then feeds the result of that function along with the second item emitted
3396-
* by an Observable into the same function, and so on until all items have been emitted by the
3397-
* source Observable, emitting the result of each of these iterations. It emits the result of
3398-
* each of these iterations as a sequence from the returned Observable. This sort of function is
3399-
* sometimes called an accumulator.
3400-
* <p>
3401-
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/scan.png">
3402-
*
3403-
* @param accumulator
3404-
* An accumulator function to be invoked on each element from the sequence whose
3405-
* result will be sent via <code>onNext</code> and used in the next accumulator call
3406-
* (if applicable).
3407-
*
3408-
* @return an Observable sequence whose elements are the result of accumulating the output from
3409-
* the list of Observables.
3410-
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211665(v%3Dvs.103).aspx">MSDN: Observable.Scan</a>
3318+
* Used by dynamic languages.
3319+
*
3320+
* @see #scan(Func2)
34113321
*/
34123322
public Observable<T> scan(final Object accumulator) {
34133323
return scan(this, accumulator);
@@ -3437,23 +3347,9 @@ public <R> Observable<R> scan(R initialValue, Func2<R, T, R> accumulator) {
34373347
}
34383348

34393349
/**
3440-
* Returns an Observable that applies a function of your choosing to the first item emitted by a
3441-
* source Observable, then feeds the result of that function along with the second item emitted
3442-
* by an Observable into the same function, then feeds the result of that function along with the
3443-
* third item into the same function, and so on, emitting the result of each of these
3444-
* iterations. This sort of function is sometimes called an accumulator.
3445-
* <p>
3446-
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/scan.png">
3447-
*
3448-
* @param initialValue
3449-
* The initial (seed) accumulator value.
3450-
* @param accumulator
3451-
* An accumulator function to be invoked on each element from the sequence whose result
3452-
* will be sent via <code>onNext</code> and used in the next accumulator call (if
3453-
* applicable).
3454-
* @return an Observable sequence whose elements are the result of accumulating the output from
3455-
* the list of Observables.
3456-
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211665(v%3Dvs.103).aspx">MSDN: Observable.Scan</a>
3350+
* Used by dynamic languages.
3351+
*
3352+
* @see #scan(Object, Func2)
34573353
*/
34583354
public <R> Observable<R> scan(final R initialValue, final Object accumulator) {
34593355
return scan(this, initialValue, accumulator);

0 commit comments

Comments
 (0)