- java.lang.Object
-
- io.smallrye.mutiny.math.Math
-
public class Math extends java.lang.ObjectA set of Mutiny operators related to various mathematical functions. These operators are intended to be used usingplug. For example:multi.plug(Math.count())
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.lang.Number>
java.util.function.Function<Multi<T>,Multi<java.lang.Double>>average()Emits the average of the items previously emitted by the upstream.static <T> java.util.function.Function<Multi<T>,Multi<java.lang.Long>>count()Emits the number of items emitted by the upstream.static <T> java.util.function.Function<Multi<T>,Multi<Tuple2<java.lang.Long,T>>>index()Emits the index (0-based) of items emitted by the upstream.static <T extends java.lang.Comparable<T>>
java.util.function.Function<Multi<T>,Multi<T>>max()Emits the maximum of the item emitted by the upstream.static <T extends java.lang.Number & java.lang.Comparable<T>>
java.util.function.Function<Multi<T>,Multi<java.lang.Double>>median()Emits the median of the items previously emitted by the upstream.static <T extends java.lang.Comparable<T>>
java.util.function.Function<Multi<T>,Multi<T>>min()Emits the minimum of the item emitted by the upstream.static <T> java.util.function.Function<Multi<T>,Multi<java.util.Map<T,java.lang.Long>>>occurrence()Emits the number of occurrences of each item emitted by the upstream.static <T extends java.lang.Number & java.lang.Comparable<T>>
java.util.function.Function<Multi<T>,Multi<Statistic<T>>>statistics()Emits statistics (average, variance, standard deviation, min, max, count, skewness and kurtosis) of the items previously emitted by the upstream.static <T extends java.lang.Number>
java.util.function.Function<Multi<T>,Multi<java.lang.Double>>sum()Emits the sum of all the items previously emitted by the upstream.static <T extends java.lang.Comparable<T>>
java.util.function.Function<Multi<T>,Multi<java.util.List<T>>>top(int count)Emits the topcountitems that have been emitted by the upstream.
-
-
-
Method Detail
-
count
public static <T> java.util.function.Function<Multi<T>,Multi<java.lang.Long>> count()
Emits the number of items emitted by the upstream. On each received item, the new count is emitted downstream.The final count can be retrieved using
multi.plug(Math.count()).collect().last(). Do not use that approach on unbounded streams.If the upstream emits a failure, the failure is propagated downstream. If the upstream completes without having emitted any item, 0 is emitted, followed by the completion event.
- Type Parameters:
T- the type of item emitted by the upstream- Returns:
- a multi emitting the number of items emitted by the upstream
-
sum
public static <T extends java.lang.Number> java.util.function.Function<Multi<T>,Multi<java.lang.Double>> sum()
Emits the sum of all the items previously emitted by the upstream. On each received item, the new sum is emitted downstream.The final sum can be retrieved using
multi.plug(Math.sum()).collect().last(). Do not use that approach on unbounded streams.If the upstream emits a failure, the failure is propagated downstream. If the upstream completes without having emitted any item, 0 is emitted, followed by the completion event.
Note the the sum are provided as
Double.- Type Parameters:
T- the type of item emitted by the upstream- Returns:
- a multi emitting the sum of the items emitted by the upstream
-
index
public static <T> java.util.function.Function<Multi<T>,Multi<Tuple2<java.lang.Long,T>>> index()
Emits the index (0-based) of items emitted by the upstream. On each received item, the new index structure is emitted downstream.The index is given as a
Tuple2<Long, T>, with the first item is the index and the second item is the item.If the upstream emits a failure, the failure is propagated downstream. If the upstream completes without having emitted any item, it sends the completion event.
- Type Parameters:
T- the type of item emitted by the upstream- Returns:
- a multi emitting the tuples containing the index and the item emitted by the upstream
-
average
public static <T extends java.lang.Number> java.util.function.Function<Multi<T>,Multi<java.lang.Double>> average()
Emits the average of the items previously emitted by the upstream. On each received item, the new average is emitted downstream.The final average can be retrieved using
multi.plug(Math.average()).collect().last(). Do not use that approach on unbounded streams.If the upstream emits a failure, the failure is propagated downstream. If the upstream completes without having emitted any item, 0.0 is emitted, followed by the completion event.
- Type Parameters:
T- the type of item emitted by the upstream- Returns:
- a multi emitting the average of the items emitted by the upstream
-
median
public static <T extends java.lang.Number & java.lang.Comparable<T>> java.util.function.Function<Multi<T>,Multi<java.lang.Double>> median()
Emits the median of the items previously emitted by the upstream. On each received item, the new median is emitted downstream.Do not use that approach on unbounded streams.
The final median can be retrieved using
multi.plug(Math.median()).collect().last().If the upstream emits a failure, the failure is propagated downstream. If the upstream completes without having emitted any item, the completion event is sent without any item emitted before.
Note: The median is a measure of central tendency. It represents the value for which 50% of observations a lower and 50% are higher. Put simply, it is the value at the center of the sorted observations.
- Type Parameters:
T- the type of item emitted by the upstream- Returns:
- a multi emitting the median of the items emitted by the upstream
-
statistics
public static <T extends java.lang.Number & java.lang.Comparable<T>> java.util.function.Function<Multi<T>,Multi<Statistic<T>>> statistics()
Emits statistics (average, variance, standard deviation, min, max, count, skewness and kurtosis) of the items previously emitted by the upstream. On each received item, a new statistic object is emitted downstream.The final average can be retrieved using
multi.plug(Math.statistics()).collect().last(). Do not use that approach on unbounded streams.If the upstream emits a failure, the failure is propagated downstream.
- Type Parameters:
T- the type of item emitted by the upstream- Returns:
- a multi emitting the statistics of the items emitted by the upstream
-
min
public static <T extends java.lang.Comparable<T>> java.util.function.Function<Multi<T>,Multi<T>> min()
Emits the minimum of the item emitted by the upstream. Each time that the upstream emits an item, this operator check if this item is smaller than the previous minimum. If so, it emits the new minimum downstream.The final minimum can be retrieved using
multi.plug(Math.min()).collect().last(). Do not use that approach on unbounded streams.This operator uses
Comparableitems, the theComparable.compareTo(Object)method is used to determine the minimum.If the upstream emits a failure, the failure is propagated downstream. If the upstream completes without having emitted any item, 0 is emitted, followed by the completion event.
- Type Parameters:
T- the type of item emitted by the upstream- Returns:
- a multi emitting the smallest item emitted by the upstream. The operator emits a new minimum every time a new minimum is received from the upstream.
-
max
public static <T extends java.lang.Comparable<T>> java.util.function.Function<Multi<T>,Multi<T>> max()
Emits the maximum of the item emitted by the upstream. Each time that the upstream emits an item, this operator check if this item is larger than the previous maximum. If so, it emits the new maximum downstream.The final minimum can be retrieved using
multi.plug(Math.max()).collect().last(). Do not use that approach on unbounded streams.This operator uses
Comparableitems, the theComparable.compareTo(Object)method is used to determine the maximum.If the upstream emits a failure, the failure is propagated downstream. If the upstream completes without having emitted any item, 0 is emitted, followed by the completion event.
- Type Parameters:
T- the type of item emitted by the upstream- Returns:
- a multi emitting the largest item emitted by the upstream. The operator emits a new maximum every time a new maximum is received from the upstream.
-
top
public static <T extends java.lang.Comparable<T>> java.util.function.Function<Multi<T>,Multi<java.util.List<T>>> top(int count)
Emits the topcountitems that have been emitted by the upstream. This operator sorts the topcountitems from the upstream and emits the ranking.On each received item, the new ranking is emitted downstream if the ranking changes.
The final ranking can be retrieved using
multi.plug(Math.top(3)).collect().last(). Do not use that approach on unbounded streams.If the upstream emits a failure, the failure is propagated downstream. If the upstream completes without having emitted any item, it emits the completion event.
This operator maintains a sorted ranking of the item emitted by the upstream. The hold structured is cleared on termination (including on cancellation). It compares the item using the
Comparable.compareTo(Object)method. Each time that the maintained ranking changes, it emits the newly computed ranking downstream. That emitted structure is aList<T>containing at mostcountitems.- Type Parameters:
T- the type of item emitted by the upstream- Parameters:
count- the number of items composing the ranking, for example, 3 for a top 3, 10 for a top 10.- Returns:
- a multi emitting the top x items emitted by the upstream
-
occurrence
public static <T> java.util.function.Function<Multi<T>,Multi<java.util.Map<T,java.lang.Long>>> occurrence()
Emits the number of occurrences of each item emitted by the upstream.This operator keeps track all of the item emitted by the upstream and stores how many times each items is emitted. Do not use this operator if the item domain is unbounded.
After each emitted item, this operator emits a
Map<T, Long>containing for each seen item, how many times they have been seen.If the upstream sends the completion even before having sent any item, this operators emits an empty map, followed with the completion event. If the upstream emits a failure, the failure is passed downstream.
On termination, including cancellation, the hold counts are cleared.
- Type Parameters:
T- the type of item, must be a validHashMapkey.- Returns:
- the multi emitting the number of occurrences for each item.
-
-