com.g2forge.alexandria.java.function.IConsumer1 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.function.Consumer;
@FunctionalInterface
public interface IConsumer1 extends Consumer, IConsumer {
public static IConsumer1 create(IConsumer1 consumer) {
return consumer;
}
@SafeVarargs
public static IConsumer1 fanOut(IConsumer1... consumers) {
return input -> {
for (IConsumer1 consumer : consumers) {
consumer.accept(input);
}
};
}
public static IConsumer1 once(IConsumer1 consumer) {
return new IConsumer1() {
protected boolean called = false;
@Override
public void accept(I input) {
if (called) throw new IllegalStateException("Can only be called once!");
try {
consumer.accept(input);
} finally {
called = true;
}
}
};
}
public default Runnable curry(I input) {
return () -> this.accept(input);
}
}