reactor-kotlin-extensions / reactor.kotlin.extra.math / reactor.core.publisher.Flux / averageAll

averageAll

fun <reified T : Number> Flux<T>.averageAll(): Mono<T>

General purpose extension function to compute the average of all values emitted by a Flux of Number and return it as a Mono. The resultant Mono will have the same Number type as the input Flux

If the result type (or precision) needs to be changed then a specific averageAsType() method should be used in preference to this method. e.g. averageAsDouble() can be used to compute the average as a Mono of Double

Author
Mark Pruden

Since
1.1.5

inline fun <T : Any, reified R : Number> Flux<T>.averageAll(noinline mapper: (T) -> R): Mono<R>

General purpose extension function to map arbitrary values in a Flux to Numbers and return the average of these Numbers as a Mono of Number. The resultant Mono will have the same Number type as the output of the mapping function

If the result type (or precision) needs to be changed then a specific averageAsType() method should be used in preference to this method. e.g. averageAsDouble() can be used to compute the average as a Mono of Double

Parameters

mapper - a lambda converting values to Number

Author
Mark Pruden

Since
1.1.5