Average
calculates the average of numbers emitted by an Observable and emits this average
See Also
Language-Specific Information
RxGroovy averageDouble averageFloat averageInteger averageLong
In RxGroovy, this operator is not in the ReactiveX core, but is part of the distinct rxjava-math
module, where it is implemented with four type-specific operators: averageDouble
, averageFloat
, averageInteger
, and averageLong
. The following example shows how these operators work:
Sample Code
def myObservable = Observable.create({ aSubscriber -> if(false == aSubscriber.isUnsubscribed()) aSubscriber.onNext(4); if(false == aSubscriber.isUnsubscribed()) aSubscriber.onNext(3); if(false == aSubscriber.isUnsubscribed()) aSubscriber.onNext(2); if(false == aSubscriber.isUnsubscribed()) aSubscriber.onNext(1); if(false == aSubscriber.isUnsubscribed()) aSubscriber.onCompleted(); }); Observable.averageInteger(myObservable).subscribe( { println(it); }, // onNext { println("Error encountered"); }, // onError { println("Sequence complete"); } // onCompleted );
2 Sequence complete
This operator will fail with an IllegalArgumentException
if the source Observable does not emit any items.
RxJava 1․x averageDouble averageFloat averageInteger averageLong
This operator is not in the RxJava core, but is part of the distinct rxjava-math
module, where it is implemented with four type-specific operators: averageDouble
, averageFloat
, averageInteger
, and averageLong
.
This operator will fail with an IllegalArgumentException
if the source Observable does not emit any items.
RxJS average
average
is found in the following distributions:
rx.all.js
rx.all.compat.js
rx.aggregates.js
It requires one of the following:
rx.js
rx.compat.js
rx.lite.js
rx.lite.compat.js
RxPHP average
© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/average.html