diff options
| author | Ben Culkin <scorpress@gmail.com> | 2022-09-16 18:35:06 -0400 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2022-09-16 18:35:06 -0400 |
| commit | bbefaad1de12cea3210593c17db6e12334eb7903 (patch) | |
| tree | a7e4165b51ecf319eb41063f8e7f9b10d820020e /src/main/java/bjc/data/Pair.java | |
| parent | e43dc808d7304b90327c1def4452f6e3d9946983 (diff) | |
Adjust a few things
Diffstat (limited to 'src/main/java/bjc/data/Pair.java')
| -rw-r--r-- | src/main/java/bjc/data/Pair.java | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/main/java/bjc/data/Pair.java b/src/main/java/bjc/data/Pair.java index baf1894..1d4be5e 100644 --- a/src/main/java/bjc/data/Pair.java +++ b/src/main/java/bjc/data/Pair.java @@ -1,5 +1,8 @@ package bjc.data; +import java.util.Formattable; +import java.util.FormattableFlags; +import java.util.Formatter; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; @@ -18,7 +21,7 @@ import bjc.funcdata.theory.Bifunctor; * The type of the right side of the pair. * */ -public interface Pair<LeftType, RightType> extends Bifunctor<LeftType, RightType> { +public interface Pair<LeftType, RightType> extends Bifunctor<LeftType, RightType>, Formattable { /** * Bind a function across the values in this pair. * @@ -247,4 +250,13 @@ public interface Pair<LeftType, RightType> extends Bifunctor<LeftType, RightType public static <Left, Right> Pair<Left, Right> pair(Left left, Right right) { return new SimplePair<>(left, right); } + + @Override + default void formatTo(Formatter formatter, int flags, int width, int precision) { + if ((flags & FormattableFlags.ALTERNATE) != 0) { + formatter.format("(%s, %s)", getLeft(), getRight()); + } else { + formatter.format("Pair [l=%s, r=%s", getLeft(), getRight()); + } + } } |
