com.aol.cyclops.streams.future.DoubleOperatorsMixin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cyclops-streams Show documentation
Show all versions of cyclops-streams Show documentation
Sequential Streams and Stream Utilities for Java 8
package com.aol.cyclops.streams.future;
import java.util.DoubleSummaryStatistics;
import java.util.OptionalDouble;
import java.util.concurrent.CompletableFuture;
import java.util.function.ToDoubleFunction;
import java.util.stream.DoubleStream;
import com.aol.cyclops.sequence.future.DoubleOperators;
import com.aol.cyclops.streams.HasExec;
import com.aol.cyclops.streams.HasStream;
public interface DoubleOperatorsMixin extends DoubleOperators,HasStream, HasExec{
/**
* Perform an asynchronous sum operation
* @see java.util.stream.Stream#mapToDouble(ToDoubleFunction)
* @see java.util.stream.DoubleStream#sum()
* */
default CompletableFuture sumDouble(ToDoubleFunction fn){
return CompletableFuture.supplyAsync(()->getStream()
.flatMapToDouble(t-> DoubleStream.of(fn.applyAsDouble(t)))
.sum(),getExec());
}
/**
* Perform an asynchronous max operation
* @see java.util.stream.Stream#mapToDouble(ToDoubleFunction)
* @see java.util.stream.DoubleStream#max()
* */
default CompletableFuture maxDouble(ToDoubleFunction fn){
return CompletableFuture.supplyAsync(()->getStream()
.flatMapToDouble(t-> DoubleStream.of(fn.applyAsDouble(t)))
.max(),getExec());
}
/**
* Perform an asynchronous min operation
* @see java.util.stream.Stream#mapToDouble(ToDoubleFunction)
* @see java.util.stream.DoubleStream#min()
* */
default CompletableFuture minDouble(ToDoubleFunction fn){
return CompletableFuture.supplyAsync(()->getStream()
.flatMapToDouble(t-> DoubleStream.of(fn.applyAsDouble(t)))
.min(),getExec());
}
/**
* Perform an asynchronous average operation
* @see java.util.stream.Stream#mapToDouble(ToDoubleFunction)
* @see java.util.stream.DoubleStream#average()
* */
default CompletableFuture averageDouble(ToDoubleFunction fn){
return CompletableFuture.supplyAsync(()->getStream()
.flatMapToDouble(t-> DoubleStream.of(fn.applyAsDouble(t)))
.average(),getExec());
}
/**
* Perform an asynchronous summaryStatistics operation
* @see java.util.stream.Stream#mapToDouble(ToDoubleFunction)
* @see java.util.stream.DoubleStream#summaryStatistics()
* */
default CompletableFuture summaryStatisticsDouble(ToDoubleFunction fn){
return CompletableFuture.supplyAsync(()->getStream()
.flatMapToDouble(t-> DoubleStream.of(fn.applyAsDouble(t)))
.summaryStatistics(),getExec());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy