Skip to content

Commit

Permalink
fixed method signatures and respective javadocs of various aggregate/…
Browse files Browse the repository at this point in the history
…reduce/scan overloads
  • Loading branch information
jmhofer committed May 7, 2013
1 parent 0f38936 commit c3ef9a1
Showing 1 changed file with 71 additions and 175 deletions.
246 changes: 71 additions & 175 deletions rxjava-core/src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1696,30 +1696,9 @@ public static <T> Observable<T> reduce(Observable<T> sequence, Func2<T, T, T> ac
}

/**
* Returns an Observable that applies a function of your choosing to the first item emitted by a
* source Observable, then feeds the result of that function along with the second item emitted
* by an Observable into the same function, and so on until all items have been emitted by the
* source Observable, emitting the final result from the final call to your function as its sole
* output.
* <p>
* 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>
* method that does a similar operation on lists.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/reduce.png">
* Used by dynamic languages.
*
* @param <T>
* the type item emitted by the source Observable
* @param sequence
* the source Observable
* @param accumulator
* an accumulator function to be invoked on each element from the sequence, whose
* result will be used in the next accumulator call (if applicable)
*
* @return an Observable that emits a single element that is the result of accumulating the
* output from applying the accumulator to the sequence of items emitted by the source
* Observable
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
* @see #reduce(Observable, Func2)
*/
public static <T> Observable<T> reduce(final Observable<T> sequence, final Object accumulator) {
@SuppressWarnings("rawtypes")
Expand All @@ -1735,6 +1714,22 @@ public T call(T t1, T t2) {
});
}

/**
* @see #reduce(Observable, Func2)
*/
public static <T> Observable<T> aggregate(Observable<T> sequence, Func2<T, T, T> accumulator) {
return reduce(sequence, accumulator);
}

/**
* Used by dynamic languages.
*
* @see #reduce(Observable, Func2)
*/
public static <T> Observable<T> aggregate(Observable<T> sequence, Object accumulator) {
return reduce(sequence, accumulator);
}

/**
* Returns an Observable that applies a function of your choosing to the first item emitted by a
* source Observable, then feeds the result of that function along with the second item emitted
Expand Down Expand Up @@ -1770,33 +1765,9 @@ public static <T, R> Observable<R> reduce(Observable<T> sequence, R initialValue
}

/**
* Returns an Observable that applies a function of your choosing to the first item emitted by a
* source Observable, then feeds the result of that function along with the second item emitted
* by an Observable into the same function, and so on until all items have been emitted by the
* source Observable, emitting the final result from the final call to your function as its sole
* output.
* <p>
* 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>
* method that does a similar operation on lists.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/reduce.png">
* Used by dynamic languages.
*
* @param <T>
* the type item emitted by the source Observable
* @param <R>
* the type returned for each item of the target observable
* @param sequence
* the source Observable
* @param initialValue
* a seed passed into the first execution of the accumulator function
* @param accumulator
* an accumulator function to be invoked on each element from the sequence, whose
* result will be used in the next accumulator call (if applicable)
* @return an Observable that emits a single element that is the result of accumulating the
* output from applying the accumulator to the sequence of items emitted by the source
* Observable
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
* @see #reduce(Observable, Object, Func2)
*/
public static <T, R> Observable<R> reduce(final Observable<T> sequence, final R initialValue, final Object accumulator) {
@SuppressWarnings("rawtypes")
Expand All @@ -1810,6 +1781,22 @@ public R call(R r, T t) {
});
}

/**
* @see #reduce(Observable, Object, Func2)
*/
public static <T, R> Observable<R> aggregate(Observable<T> sequence, R initialValue, Func2<R, T, R> accumulator) {
return reduce(sequence, initialValue, accumulator);
}

/**
* Used by dynamic languages.
*
* @see #reduce(Observable, Object, Func2)
*/
public static <T, R> Observable<R> aggregate(Observable<T> sequence, R initialValue, Object accumulator) {
return reduce(sequence, initialValue, accumulator);
}

/**
* Returns an Observable that applies a function of your choosing to the first item emitted by a
* source Observable, then feeds the result of that function along with the second item emitted
Expand All @@ -1834,23 +1821,9 @@ public static <T> Observable<T> scan(Observable<T> sequence, Func2<T, T, T> accu
}

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

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

/**
* @see #reduce(Func2)
*/
public Observable<T> aggregate(Func2<T, T, T> accumulator) {
return reduce(accumulator);
}

/**
* Returns an Observable that applies a function of your choosing to the first item emitted by a
* source Observable, then feeds the result of that function along with the second item emitted
* by an Observable into the same function, and so on until all items have been emitted by the
* source Observable, emitting the final result from the final call to your function as its sole
* output.
* <p>
* 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> method that does a similar operation on lists.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/reduce.png">
* Used by dynamic languages.
*
* @param accumulator
* An accumulator function to be invoked on each element from the sequence, whose result
* will be used in the next accumulator call (if applicable).
*
* @return an Observable that emits a single element from the result of accumulating the output
* from the list of Observables.
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
* @see #reduce(Func2)
*/
public Observable<T> reduce(Object accumulator) {
return reduce(this, accumulator);
}

/**
* @see #reduce(Object)
* @see #reduce(Func2)
*/
public Observable<T> aggregate(Func2<T, T, T> accumulator) {
return aggregate(this, accumulator);
}

/**
* Used by dynamic languages.
*
* @see #reduce(Func2)
*/
public Observable<T> aggregate(Object accumulator) {
return reduce(accumulator);
return aggregate(this, accumulator);
}

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

/**
* @see #reduce(R, Func2)
* Used by dynamic languages.
*
* @see #reduce(Object, Func2)
*/
public <R> Observable<R> aggregate(R initialValue, Func2<R, T, R> accumulator) {
return reduce(initialValue, accumulator);
public <R> Observable<R> reduce(R initialValue, Object accumulator) {
return reduce(this, initialValue, accumulator);
}

/**
* Returns an Observable that applies a function of your choosing to the first item emitted by a
* source Observable, then feeds the result of that function along with the second item emitted
* by an Observable into the same function, and so on until all items have been emitted by the
* source Observable, emitting the final result from the final call to your function as its sole
* output.
* <p>
* 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> method that does a similar operation on lists.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/reduce.png">
*
* @param initialValue
* The initial (seed) accumulator value.
* @param accumulator
* An accumulator function to be invoked on each element from the sequence, whose
* result will be used in the next accumulator call (if applicable).
* @return an Observable that emits a single element from the result of accumulating the output
* from the list of Observables.
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229154(v%3Dvs.103).aspx">MSDN: Observable.Aggregate</a>
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
* @see #reduce(Object, Func2)
*/
public <R> Observable<R> reduce(R initialValue, Object accumulator) {
return reduce(this, initialValue, accumulator);
public <R> Observable<R> aggregate(R initialValue, Func2<R, T, R> accumulator) {
return aggregate(this, initialValue, accumulator);
}

/**
* @see #reduce(R, Object)
* Used by dynamic languages.
*
* @see #reduce(Object, Func2)
*/
public <R> Observable<R> aggregate(R initialValue, Object accumulator) {
return reduce(initialValue, accumulator);
return aggregate(this, initialValue, accumulator);
}

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

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

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

0 comments on commit c3ef9a1

Please sign in to comment.