All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aol.cyclops.streams.future.IntOperatorsMixin Maven / Gradle / Ivy

There is a newer version: 7.3.1
Show newest version
package com.aol.cyclops.streams.future;

import java.util.IntSummaryStatistics;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.concurrent.CompletableFuture;
import java.util.function.ToIntFunction;
import java.util.stream.IntStream;

import com.aol.cyclops.sequence.future.IntOperators;
import com.aol.cyclops.streams.HasExec;
import com.aol.cyclops.streams.HasStream;

public interface IntOperatorsMixin  extends IntOperators,HasStream, HasExec{
	
	/**
	 * Perform an asynchronous sum operation
	 * @see java.util.stream.Stream#mapToInt(ToIntFunction)
	 * 	 @see java.util.stream.IntStream#sum()
	 * */
	default  CompletableFuture sumInt(ToIntFunction fn){
		
		return CompletableFuture.supplyAsync(()->getStream()
								.flatMapToInt(t-> IntStream.of(fn.applyAsInt(t)))
								.sum(),getExec());
				
	}
	/**
	 * Perform an asynchronous max operation
	 * @see java.util.stream.Stream#mapToInt(ToIntFunction)
	 * 	 @see java.util.stream.IntStream#max()
	 * */
	default  CompletableFuture maxInt(ToIntFunction fn){
		
		return CompletableFuture.supplyAsync(()->getStream()
								.flatMapToInt(t-> IntStream.of(fn.applyAsInt(t)))
								.max(),getExec());
				
	}
	/**
	 * Perform an asynchronous min operation
	 * @see java.util.stream.Stream#mapToInt(ToIntFunction)
	 * 	 @see java.util.stream.IntStream#min()
	 * */
	default  CompletableFuture minInt(ToIntFunction fn){
		
		return CompletableFuture.supplyAsync(()->getStream()
								.flatMapToInt(t-> IntStream.of(fn.applyAsInt(t)))
								.min(),getExec());
				
	}
	/**
	 * Perform an asynchronous average operation
	 * @see java.util.stream.Stream#mapToInt(ToIntFunction)
	 * 	 @see java.util.stream.IntStream#average()
	 * */
	default CompletableFuture averageInt(ToIntFunction fn){
		
		return CompletableFuture.supplyAsync(()->getStream()
								.flatMapToInt(t-> IntStream.of(fn.applyAsInt(t)))
								.average(),getExec());
				
	}
	/**
	 * Perform an asynchronous summaryStatistics operation
	 * @see java.util.stream.Stream#mapToInt(ToIntFunction)
	 * 	 @see java.util.stream.IntStream#summaryStatistics()
	 * */
	default  CompletableFuture summaryStatisticsInt(ToIntFunction fn){
		
		return CompletableFuture.supplyAsync(()->getStream()
								.flatMapToInt(t-> IntStream.of(fn.applyAsInt(t)))
								.summaryStatistics(),getExec());
			
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy