Skip to content

Commit f11d67c

Browse files
Merge pull request ReactiveX#587 from akarnokd/LongCount
Operation LongCount
2 parents 449fee9 + 5d2f947 commit f11d67c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3873,6 +3873,7 @@ public Observable<T> reduce(Func2<T, T, T> accumulator) {
38733873
* source Observable as its single item
38743874
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-Operators#count">RxJava Wiki: count()</a>
38753875
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229470.aspx">MSDN: Observable.Count</a>
3876+
* @see #longCount()
38763877
*/
38773878
public Observable<Integer> count() {
38783879
return reduce(0, new Func2<Integer, T, Integer>() {
@@ -5193,6 +5194,27 @@ public Observable<T> last() {
51935194
return create(OperationLast.last(this));
51945195
}
51955196

5197+
/**
5198+
* Returns an Observable that counts the total number of items in the
5199+
* source Observable as a 64 bit long.
5200+
* <p>
5201+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/count.png">
5202+
*
5203+
* @return an Observable that emits the number of counted elements of the
5204+
* source Observable as its single, 64 bit long item
5205+
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-Operators#count">RxJava Wiki: count()</a>
5206+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229120.aspx">MSDN: Observable.LongCount</a>
5207+
* @see #count()
5208+
*/
5209+
public Observable<Long> longCount() {
5210+
return reduce(0L, new Func2<Long, T, Long>() {
5211+
@Override
5212+
public Long call(Long t1, T t2) {
5213+
return t1 + 1;
5214+
}
5215+
});
5216+
}
5217+
51965218
/**
51975219
* Converts an Observable into a {@link BlockingObservable} (an Observable
51985220
* with blocking operators).

0 commit comments

Comments
 (0)