diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-04-13 18:43:13 -0400 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-04-13 18:43:13 -0400 |
| commit | f51f6da7319787348c38b875652b5c0e9f88c8aa (patch) | |
| tree | 943888fc724da2d2dedd89abec99dcbfcc089fd0 /src/main/java/bjc/data/IPair.java | |
| parent | 9052ed6da37af23ea82588d248f409e60a33c6cb (diff) | |
Cleanup pass
Pass to do some cleanups
Diffstat (limited to 'src/main/java/bjc/data/IPair.java')
| -rw-r--r-- | src/main/java/bjc/data/IPair.java | 122 |
1 files changed, 65 insertions, 57 deletions
diff --git a/src/main/java/bjc/data/IPair.java b/src/main/java/bjc/data/IPair.java index 0c63f16..5b1298e 100644 --- a/src/main/java/bjc/data/IPair.java +++ b/src/main/java/bjc/data/IPair.java @@ -12,10 +12,10 @@ import bjc.funcdata.theory.Bifunctor; * @author ben * * @param <LeftType> - * The type of the left side of the pair. + * The type of the left side of the pair. * * @param <RightType> - * The type of the right side of the pair. + * The type of the right side of the pair. * */ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightType> { @@ -23,103 +23,105 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp * Bind a function across the values in this pair. * * @param <BoundLeft> - * The type of the bound left. + * The type of the bound left. * * @param <BoundRight> - * The type of the bound right. + * The type of the bound right. * * @param binder - * The function to bind with. + * The function to bind with. * * @return The bound pair. */ - public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder); + public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> + bind(BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder); /** * Bind a function to the left value in this pair. * * @param <BoundLeft> - * The type of the bound value. + * The type of the bound value. * * @param leftBinder - * The function to use to bind. + * The function to use to bind. * * @return A pair with the left type bound. */ - public <BoundLeft> IPair<BoundLeft, RightType> bindLeft( - Function<LeftType, IPair<BoundLeft, RightType>> leftBinder); + public <BoundLeft> IPair<BoundLeft, RightType> + bindLeft(Function<LeftType, IPair<BoundLeft, RightType>> leftBinder); /** * Bind a function to the right value in this pair. * * @param <BoundRight> - * The type of the bound value. + * The type of the bound value. * * @param rightBinder - * The function to use to bind. + * The function to use to bind. * * @return A pair with the right type bound. */ - public <BoundRight> IPair<LeftType, BoundRight> bindRight( - Function<RightType, IPair<LeftType, BoundRight>> rightBinder); + public <BoundRight> IPair<LeftType, BoundRight> + bindRight(Function<RightType, IPair<LeftType, BoundRight>> rightBinder); /** * Pairwise combine two pairs together. * * @param <OtherLeft> - * The left type of the other pair. + * The left type of the other pair. * * @param <OtherRight> - * The right type of the other pair. + * The right type of the other pair. * * @param otherPair - * The pair to combine with. + * The pair to combine with. * * @return The pairs, pairwise combined together. */ - public default <OtherLeft, OtherRight> IPair<IPair<LeftType, OtherLeft>, IPair<RightType, OtherRight>> combine( - final IPair<OtherLeft, OtherRight> otherPair) { - return combine(otherPair, Pair<LeftType, OtherLeft>::new, Pair<RightType, OtherRight>::new); + public default <OtherLeft, OtherRight> + IPair<IPair<LeftType, OtherLeft>, IPair<RightType, OtherRight>> + combine(final IPair<OtherLeft, OtherRight> otherPair) { + return combine(otherPair, Pair<LeftType, OtherLeft>::new, + Pair<RightType, OtherRight>::new); } /** * Combine the contents of two pairs together. * * @param <OtherLeft> - * The type of the left value of the other pair. + * The type of the left value of the other pair. * * @param <OtherRight> - * The type of the right value of the other pair. + * The type of the right value of the other pair. * * @param <CombinedLeft> - * The type of the left value of the combined pair. + * The type of the left value of the combined pair. * * @param <CombinedRight> - * The type of the right value of the combined pair. + * The type of the right value of the combined pair. * * @param otherPair - * The other pair to combine with. + * The other pair to combine with. * * @param leftCombiner - * The function to combine the left values with. + * The function to combine the left values with. * * @param rightCombiner - * The function to combine the right values with. + * The function to combine the right values with. * * @return A pair with its values combined. */ - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<RightType, OtherRight, CombinedRight> rightCombiner); + public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> + IPair<CombinedLeft, CombinedRight> + combine(IPair<OtherLeft, OtherRight> otherPair, + BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, + BiFunction<RightType, OtherRight, CombinedRight> rightCombiner); /** - * Immediately perfom the specified action with the contents of this - * pair. + * Immediately perfom the specified action with the contents of this pair. * * @param consumer - * The action to perform on the pair. + * The action to perform on the pair. */ public default void doWith(final BiConsumer<LeftType, RightType> consumer) { merge((leftValue, rightValue) -> { @@ -130,32 +132,36 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp } @Override - default <OldLeft, OldRight, NewLeft> LeftBifunctorMap<OldLeft, OldRight, NewLeft> fmapLeft( - final Function<OldLeft, NewLeft> func) { + default <OldLeft, OldRight, NewLeft> LeftBifunctorMap<OldLeft, OldRight, NewLeft> + fmapLeft(final Function<OldLeft, NewLeft> func) { return argumentPair -> { if (!(argumentPair instanceof IPair<?, ?>)) { - final String msg = "This function can only be applied to instances of IPair"; + final String msg + = "This function can only be applied to instances of IPair"; throw new IllegalArgumentException(msg); } - final IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair; + final IPair<OldLeft, OldRight> argPair + = (IPair<OldLeft, OldRight>) argumentPair; return argPair.mapLeft(func); }; } @Override - default <OldLeft, OldRight, NewRight> RightBifunctorMap<OldLeft, OldRight, NewRight> fmapRight( - final Function<OldRight, NewRight> func) { + default <OldLeft, OldRight, NewRight> RightBifunctorMap<OldLeft, OldRight, NewRight> + fmapRight(final Function<OldRight, NewRight> func) { return argumentPair -> { if (!(argumentPair instanceof IPair<?, ?>)) { - final String msg = "This function can only be applied to instances of IPair"; + final String msg + = "This function can only be applied to instances of IPair"; throw new IllegalArgumentException(msg); } - final IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair; + final IPair<OldLeft, OldRight> argPair + = (IPair<OldLeft, OldRight>) argumentPair; return argPair.mapRight(func); }; @@ -187,15 +193,15 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp * Doesn't modify the pair. * * @param <NewLeft> - * The new type of the left part of the pair. + * The new type of the left part of the pair. * * @param mapper - * The function to use to transform the left part of the - * pair. + * The function to use to transform the left part of the pair. * * @return The pair, with its left part transformed. */ - public <NewLeft> IPair<NewLeft, RightType> mapLeft(Function<LeftType, NewLeft> mapper); + public <NewLeft> IPair<NewLeft, RightType> + mapLeft(Function<LeftType, NewLeft> mapper); /** * Transform the value on the right side of the pair. @@ -203,36 +209,38 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp * Doesn't modify the pair. * * @param <NewRight> - * The new type of the right part of the pair. + * The new type of the right part of the pair. * * @param mapper - * The function to use to transform the right part of the - * pair. + * The function to use to transform the right part of the + * pair. * * @return The pair, with its right part transformed. */ - public <NewRight> IPair<LeftType, NewRight> mapRight(Function<RightType, NewRight> mapper); + public <NewRight> IPair<LeftType, NewRight> + mapRight(Function<RightType, NewRight> mapper); /** * Merge the two values in this pair into a single value. * * @param <MergedType> - * The type of the single value. + * The type of the single value. * * @param merger - * The function to use for merging. + * The function to use for merging. * * @return The pair, merged into a single value. */ - public <MergedType> MergedType merge(BiFunction<LeftType, RightType, MergedType> merger); + public <MergedType> MergedType + merge(BiFunction<LeftType, RightType, MergedType> merger); /** * Static pair constructor. - * + * * @param left - * The left side of the pair. + * The left side of the pair. * @param right - * The right side of the pair. + * The right side of the pair. * @return A pair, with the specified left/right side. */ public static <T1, T2> IPair<T1, T2> pair(T1 left, T2 right) { |
