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

com.g2forge.alexandria.java.function.IFunction1 Maven / Gradle / Ivy

There is a newer version: 0.0.18
Show newest version
package com.g2forge.alexandria.java.function;

import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;

@FunctionalInterface
public interface IFunction1 extends Function, IFunction {
	@SuppressWarnings("unchecked")
	public static  IFunction1 cast() {
		return i -> (O) i;
	}

	public static  IFunction1 create(IFunction1 function) {
		return function;
	}

	public static  IFunction1 identity() {
		return t -> t;
	}

	@SuppressWarnings("unchecked")
	public static  IFunction1 isInstanceOf(Class type) {
		return i -> type.isInstance(i) ? (O) i : null;
	}

	public default  IFunction1 andThen(IFunction1 f) {
		return i -> f.apply(apply(i));
	}

	public default Supplier compose(Supplier before) {
		Objects.requireNonNull(before);
		return () -> apply(before.get());
	}

	public default Supplier curry(I input) {
		return () -> apply(input);
	}

	public default  IFunction1 lift(T equal, IFunction1 lift) {
		return i -> {
			final O o = apply(i);
			if (i == o) return equal;
			return lift.apply(o);
		};
	}

	public default IConsumer1 noReturn() {
		return i -> apply(i);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy