com.github.dakusui.crest.utils.printable.PrintableFunction Maven / Gradle / Ivy
package com.github.dakusui.crest.utils.printable;
import java.util.Objects;
import java.util.function.Function;
public class PrintableFunction implements Function {
private final String s;
private final Function super T, ? extends R> function;
PrintableFunction(String s, Function super T, ? extends R> function) {
this.s = Objects.requireNonNull(s);
this.function = Objects.requireNonNull(function);
}
@Override
public R apply(T t) {
return this.function.apply(t);
}
public Function compose(Function super V, ? extends T> before) {
Objects.requireNonNull(before);
return new PrintableFunction<>(String.format("%s%s", before, s), this.function.compose(before));
}
public Function andThen(Function super R, ? extends V> after) {
Objects.requireNonNull(after);
return new PrintableFunction<>(String.format("%s%s", s, after), this.function.andThen(after));
}
@Override
public String toString() {
return s;
}
public static PrintableFunction create(String s, Function super T, ? extends R> function) {
return new PrintableFunction<>(s, function);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy