package base; import java.util.Map; import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.function.UnaryOperator; /** * @author Georgiy Korneev (kgeorgiy@kgeorgiy.info) */ @SuppressWarnings({"StaticMethodOnlyUsedInOneClass", "unused"}) public record Pair(F first, S second) { public static Pair of(final F first, final S second) { return new Pair<>(first, second); } public static Pair of(final Map.Entry e) { return of(e.getKey(), e.getValue()); } public static UnaryOperator> lift(final UnaryOperator f, final UnaryOperator s) { return p -> of(f.apply(p.first), s.apply(p.second)); } public static BinaryOperator> lift(final BinaryOperator f, final BinaryOperator s) { return (p1, p2) -> of(f.apply(p1.first, p2.first), s.apply(p1.second, p2.second)); } public static Function> tee( final Function f, final Function s ) { return t -> of(f.apply(t), s.apply(t)); } @Override public String toString() { return "(" + first + ", " + second + ")"; } public Pair second(final R second) { return new Pair<>(first, second); } }