private static <T> Function<List<T>, Optional<Double>> covarianceFinisher(
        ToDoubleFunction<? super T> functionX,
        ToDoubleFunction<? super T> functionY,
        BiFunction<List<T>, ToDoubleFunction<? super T>, Double> sumOrAvg
    ) {
        return l -> {
            if (l.isEmpty())
                return Optional.empty();
            else if (l.size() == 1)
                return Optional.of(0.0);

            double avgX = avg0(l, functionX);
            double avgY = avg0(l, functionY);
            return Optional.of(sumOrAvg.apply(l, t -> (functionX.applyAsDouble(t) - avgX) * (functionY.applyAsDouble(t) - avgY)));
        };
    }
Get a {@link Collector} that calculates the <code>COVAR_POP()</code> function.
jOOL/src/main/java/org/jooq/lambda/Agg.java