I have a method that returns a Flux
, let\'s suppose SensorData has a field measure: Integer
.
I would like to calculate the av
Another way of doing it with an auxiliary object:
val average = sensorFlux.map { it.measure }
.map { Measure(1, it) }
.reduce { t: Measure, u: Measure -> Measure(t.elements + u.elements, t.sum + u.sum) }
.map { it.sum / it.elements }
---
data class Measure(var elements: Int, var sum: Long)
Mono<Double> average = sensorFlux.collect(Collectors.averagingInt(SensorData::getMeasure))