From dca8e9f586fd595a7995f07788318fb92b8cce79 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 28 Jul 2016 16:44:36 -0400 Subject: Format/Cleanup pass --- BJC-Utils2/src/main/java/bjc/utils/data/IPair.java | 108 ++++++++++----------- 1 file changed, 51 insertions(+), 57 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/IPair.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java index f94d656..a2a635f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java @@ -56,6 +56,46 @@ public interface IPair public IPair bindRight( Function> rightBinder); + /** + * Pairwise combine two pairs together + * + * @param + * The left type of the other pair + * @param + * The right type of the other pair + * @param otherPair + * The pair to combine with + * @return The pairs, pairwise combined together + */ + public default IPair, IPair> combine( + IPair otherPair) { + return combine(otherPair, + (left, otherLeft) -> new Pair<>(left, otherLeft), + (right, otherRight) -> new Pair<>(right, otherRight)); + } + + /** + * Combine the contents of two pairs together + * + * @param + * The type of the left value of the other pair + * @param + * The type of the right value of the other pair + * @param + * The type of the left value of the combined pair + * @param + * The type of the right value of the combined pair + * @param otherPair + * The other pair to combine with + * @param leftCombiner + * @param rightCombiner + * @return A pair with its values combined + */ + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner); + /** * Immediately perfom the specified action with the contents of this * pair @@ -72,25 +112,22 @@ public interface IPair } @Override - default - Function, Bifunctor> - fmapLeft(Function func) { + default Function, Bifunctor> fmapLeft( + Function func) { return (argumentPair) -> { if (!(argumentPair instanceof IPair)) { throw new IllegalArgumentException( "This function can only be applied to instances of IPair"); } - IPair argPair = - (IPair) argumentPair; + IPair argPair = (IPair) argumentPair; return argPair.mapLeft(func); }; } @Override - default - Function, Bifunctor> + default Function, Bifunctor> fmapRight(Function func) { return (argumentPair) -> { @@ -99,8 +136,7 @@ public interface IPair "This function can only be applied to instances of IPair"); } - IPair argPair = - (IPair) argumentPair; + IPair argPair = (IPair) argumentPair; return argPair.mapRight(func); }; @@ -137,8 +173,8 @@ public interface IPair * pair * @return The pair, with its left part transformed */ - public IPair - mapLeft(Function mapper); + public IPair mapLeft( + Function mapper); /** * Transform the value on the right side of the pair. Doesn't modify @@ -151,8 +187,8 @@ public interface IPair * pair * @return The pair, with its right part transformed */ - public IPair - mapRight(Function mapper); + public IPair mapRight( + Function mapper); /** * Merge the two values in this pair into a single value @@ -163,48 +199,6 @@ public interface IPair * The function to use for merging * @return The pair, merged into a single value */ - public MergedType - merge(BiFunction merger); - - /** - * Combine the contents of two pairs together - * - * @param - * The type of the left value of the other pair - * @param - * The type of the right value of the other pair - * @param - * The type of the left value of the combined pair - * @param - * The type of the right value of the combined pair - * @param otherPair - * The other pair to combine with - * @param leftCombiner - * @param rightCombiner - * @return A pair with its values combined - */ - public - IPair - combine(IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner); - - /** - * Pairwise combine two pairs together - * - * @param - * The left type of the other pair - * @param - * The right type of the other pair - * @param otherPair - * The pair to combine with - * @return The pairs, pairwise combined together - */ - public default - IPair, IPair> - combine(IPair otherPair) { - return combine(otherPair, - (left, otherLeft) -> new Pair<>(left, otherLeft), - (right, otherRight) -> new Pair<>(right, otherRight)); - } + public MergedType merge( + BiFunction merger); } -- cgit v1.2.3