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

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

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

import java.util.LongSummaryStatistics;
import java.util.OptionalDouble;
import java.util.OptionalLong;
import java.util.concurrent.CompletableFuture;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
import java.util.stream.LongStream;

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

public interface LongOperatorsMixin  extends LongOperators,HasStream, HasExec{
	
	/**
	 * Perform an asynchronous sum operation
	 * @see java.util.stream.Stream#mapToLong(ToLongFunction)
	 * 	 @see java.util.stream.LongStream#sum()
	 * */
	default  CompletableFuture sumLong(ToLongFunction fn){
		
		return CompletableFuture.supplyAsync(()->getStream()
								.flatMapToLong(t-> LongStream.of(fn.applyAsLong(t)))
								.sum(),getExec());
				
	}
	/**
	 * Perform an asynchronous max operation
	 * @see java.util.stream.Stream#mapToLong(ToLongFunction)
	 * 	 @see java.util.stream.LongStream#max()
	 * */
	default  CompletableFuture maxLong(ToLongFunction fn){
		
		return CompletableFuture.supplyAsync(()->getStream()
								.flatMapToLong(t-> LongStream.of(fn.applyAsLong(t)))
								.max(),getExec());
				
	}
	/**
	 * Perform an asynchronous min operation
	 * @see java.util.stream.Stream#mapToLong(ToLongFunction)
	 * 	 @see java.util.stream.LongStream#min()
	 * */
	default  CompletableFuture minLong(ToLongFunction fn){
		
		return CompletableFuture.supplyAsync(()->getStream()
								.flatMapToLong(t-> LongStream.of(fn.applyAsLong(t)))
								.min(),getExec());
				
	}
	/**
	 * Perform an asynchronous average operation
	 * @see java.util.stream.Stream#mapToLong(ToLongFunction)
	 * 	 @see java.util.stream.LongStream#average()
	 * */
	default CompletableFuture averageLong(ToLongFunction fn){
		
		return CompletableFuture.supplyAsync(()->getStream()
								.flatMapToLong(t-> LongStream.of(fn.applyAsLong(t)))
								.average(),getExec());
				
	}
	/**
	 * Perform an asynchronous summaryStatistics operation
	 * @see java.util.stream.Stream#mapToLong(ToLongFunction)
	 * 	 @see java.util.stream.LongStream#summaryStatistics()
	 * */
	default  CompletableFuture summaryStatisticsLong(ToLongFunction fn){
		
		return CompletableFuture.supplyAsync(()->getStream()
								.flatMapToLong(t-> LongStream.of(fn.applyAsLong(t)))
								.summaryStatistics(),getExec());
			
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy