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

com.aol.cyclops.lambda.tuple.PTuple1 Maven / Gradle / Ivy

There is a newer version: 7.2.4
Show newest version
package com.aol.cyclops.lambda.tuple;

import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Function;

import com.aol.cyclops.lambda.tuple.lazymap.LazyMap1PTuple8;
import com.aol.cyclops.lambda.tuple.memo.Memo1;
import com.aol.cyclops.lambda.tuple.reorder.ReorderP1;

public interface PTuple1 extends CachedValues{
	
	default T1 v1(){
		return (T1)getCachedValues().get(0);
	}
	default T1 _1(){
		return v1();
	}

	default T1 getT1(){
		return v1();
	}
	
	default int arity(){
		return 1;
	}
	default  T apply1(Function fn){
		return fn.apply(v1());
	}
	default  T call(Function fn){
		return fn.apply(v1());
	}
	default  CompletableFuture  callAsync(Function fn){
		return CompletableFuture.completedFuture(v1()).thenApplyAsync(fn);
	}
	default  CompletableFuture applyAsync1(Function fn){
		return CompletableFuture.completedFuture(v1()).thenApplyAsync(fn);
	}
	default  CompletableFuture  callAsync(Function fn,Executor e){
		return CompletableFuture.completedFuture(v1()).thenApplyAsync(fn,e);
	}
	default  CompletableFuture applyAsync1(Function fn,Executor e){
		return CompletableFuture.completedFuture(v1()).thenApplyAsync(fn,e);
	}
	
	
	
	/**Strict mapping of the first element
	 * 
	 * @param fn Mapping function
	 * @return Tuple1
	 */
	default  PTuple1 map1(Function fn){
		return PowerTuples.tuple(fn.apply(v1()));
	}
	/**
	 * Lazily Map 1st element and memoise the result
	 * @param fn Map function
	 * @return
	 */
	default  PTuple1 lazyMap1(Function fn){
		
		return new LazyMap1PTuple8(fn,(PTuple8)this);
	}
	
	default  PTuple1 reorder(Function,NT1> v1S){

		return new ReorderP1<>(v1S, this);
	}
	
	
	default PTuple1 swap1(){
		return PowerTuples.tuple(v1());
	}
	
	default PTuple1 memo(){
			return new Memo1<>( this);
	}
	public static  PTuple1 ofTuple(Object tuple1){
		return (PTuple1)new TupleImpl(tuple1,1);
	}
	public static  PTuple1 of(T1 t1){
		return (PTuple1)new TupleImpl(Arrays.asList(t1),1);
	}



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy