com.g2forge.alexandria.java.function.IFunction1 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ax-java Show documentation
Show all versions of ax-java Show documentation
Standard Java library and the basis of the ${alexandria.name} project.
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 super O, ? extends X> f) {
return i -> f.apply(apply(i));
}
public default Supplier compose(Supplier extends I> before) {
Objects.requireNonNull(before);
return () -> apply(before.get());
}
public default Supplier curry(I input) {
return () -> apply(input);
}
public default IFunction1 lift(T equal, IFunction1 super O, ? extends T> 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);
}
}