Skip to content

Commit 5d2f947

Browse files
committed
Operation LongCount
1 parent dce9d47 commit 5d2f947

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
@@ -3871,6 +3871,7 @@ public Observable<T> reduce(Func2<T, T, T> accumulator) {
38713871
* source Observable as its single item
38723872
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-Operators#count">RxJava Wiki: count()</a>
38733873
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229470.aspx">MSDN: Observable.Count</a>
3874+
* @see #longCount()
38743875
*/
38753876
public Observable<Integer> count() {
38763877
return reduce(0, new Func2<Integer, T, Integer>() {
@@ -5172,6 +5173,27 @@ public Observable<T> last() {
51725173
return create(OperationLast.last(this));
51735174
}
51745175

5176+
/**
5177+
* Returns an Observable that counts the total number of items in the
5178+
* source Observable as a 64 bit long.
5179+
* <p>
5180+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/count.png">
5181+
*
5182+
* @return an Observable that emits the number of counted elements of the
5183+
* source Observable as its single, 64 bit long item
5184+
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-Operators#count">RxJava Wiki: count()</a>
5185+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229120.aspx">MSDN: Observable.LongCount</a>
5186+
* @see #count()
5187+
*/
5188+
public Observable<Long> longCount() {
5189+
return reduce(0L, new Func2<Long, T, Long>() {
5190+
@Override
5191+
public Long call(Long t1, T t2) {
5192+
return t1 + 1;
5193+
}
5194+
});
5195+
}
5196+
51755197
/**
51765198
* Converts an Observable into a {@link BlockingObservable} (an Observable
51775199
* with blocking operators).

0 commit comments

Comments
 (0)