From dca8e9f586fd595a7995f07788318fb92b8cce79 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 28 Jul 2016 16:44:36 -0400 Subject: Format/Cleanup pass --- .../java/bjc/utils/funcdata/theory/Bifunctor.java | 88 ++++++++++------------ 1 file changed, 41 insertions(+), 47 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata/theory') diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java index e8c74fc..d3ebdac 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java @@ -13,6 +13,43 @@ import java.util.function.Function; * */ public interface Bifunctor { + /** + * Lift a pair of functions to a single function that maps over both + * parts of a pair + * + * @param + * The old left type of the pair + * @param + * The old right type of the pair + * @param + * The new left type of the pair + * @param + * The new right type of the pair + * @param leftFunc + * The function that maps over the left of the pair + * @param rightFunc + * The function that maps over the right of the pair + * @return A function that maps over both parts of the pair + */ + public default Function, Bifunctor> bimap( + Function leftFunc, + Function rightFunc) { + Function, Bifunctor> bimappedFunc = ( + argPair) -> { + Function, Bifunctor> leftMapper = argPair + . fmapLeft(leftFunc); + + Bifunctor leftMappedFunctor = leftMapper + .apply(argPair); + Function, Bifunctor> rightMapper = leftMappedFunctor + . fmapRight(rightFunc); + + return rightMapper.apply(leftMappedFunctor); + }; + + return bimappedFunc; + } + /** * Lift a function to operate over the left part of this pair * @@ -27,9 +64,8 @@ public interface Bifunctor { * pair * @return The function lifted to work over the left side of bifunctors */ - public - Function, Bifunctor> - fmapLeft(Function func); + public Function, Bifunctor> fmapLeft( + Function func); /** * Lift a function to operate over the right part of this pair @@ -46,50 +82,8 @@ public interface Bifunctor { * @return The function lifted to work over the right side of * bifunctors */ - public - Function, Bifunctor> - fmapRight(Function func); - - /** - * Lift a pair of functions to a single function that maps over both - * parts of a pair - * - * @param - * The old left type of the pair - * @param - * The old right type of the pair - * @param - * The new left type of the pair - * @param - * The new right type of the pair - * @param leftFunc - * The function that maps over the left of the pair - * @param rightFunc - * The function that maps over the right of the pair - * @return A function that maps over both parts of the pair - */ - public default - Function, Bifunctor> - bimap(Function leftFunc, - Function rightFunc) { - Function, Bifunctor> bimappedFunc = - (argPair) -> { - Function, Bifunctor> leftMapper = - argPair. fmapLeft( - leftFunc); - - Bifunctor leftMappedFunctor = - leftMapper.apply(argPair); - Function, Bifunctor> rightMapper = - leftMappedFunctor - . fmapRight( - rightFunc); - - return rightMapper.apply(leftMappedFunctor); - }; - - return bimappedFunc; - } + public Function, Bifunctor> fmapRight( + Function func); /** * Get the value contained on the left of this bifunctor -- cgit v1.2.3