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

com.unit16.z.Tee Maven / Gradle / Ivy

package com.unit16.z;

import java.util.function.Function;


public interface Tee {

	C apply(A a, B b);

	/**
	 * Composition rules for {@link Tee}, as a presumably hip "fluid builder".
	 */
	static abstract class DSL
	implements Tee
	{
		static  Tee from(final Tee f)
		{
			return new DSL() {
				@Override public Z apply(X a, Y b) { 
					return f.apply(a, b); }
			};
		}

		public final  DSL preA(final Function f) {
			final DSL w = this;
			return new DSL() {
				@Override public C apply(S a, B b) { 
					return w.apply(f.apply(a), b); }
			};
		}
		
		public final  DSL preB(final Function f) {
			final DSL w = this;
			return new DSL() {
				@Override public C apply(A a, R b) { 
					return w.apply(a, f.apply(b)); }
			};
		}

		public final  DSL post(final Function f) {
			final DSL w = this;
			return new DSL() {
				@Override public Q apply(A a, B b) { 
					return f.apply(w.apply(a, b)); }
			};
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy