From 9ace8e5bcce74808ab0a33115017bcf200e03a96 Mon Sep 17 00:00:00 2001 From: bjculkin Date: Mon, 20 Mar 2017 19:21:42 -0400 Subject: Update --- .../java/bjc/utils/funcdata/theory/Bifunctor.java | 194 ++++++++++----------- 1 file changed, 97 insertions(+), 97 deletions(-) (limited to 'BJC-Utils2/src') 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 d6da637..8e9bbd2 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 @@ -1,97 +1,97 @@ -package bjc.utils.funcdata.theory; - -import java.util.function.Function; - -/** - * A functor over a pair of heterogenous types - * - * @author ben - * @param - * The type stored on the 'left' of the pair - * @param - * The type stored on the 'right' of the pair - * - */ -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 - * - * @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 func - * The function to lift to work over the left side of the - * pair - * @return The function lifted to work over the left side of bifunctors - */ - public Function, Bifunctor> fmapLeft( - Function func); - - /** - * Lift a function to operate over the right part of this pair - * - * @param - * The old left type of the pair - * @param - * The old right type of the pair - * @param - * The new right type of the pair - * @param func - * The function to lift to work over the right side of - * the pair - * @return The function lifted to work over the right side of bifunctors - */ - public Function, Bifunctor> fmapRight( - Function func); - - /** - * Get the value contained on the left of this bifunctor - * - * @return The value on the left side of this bifunctor - */ - public LeftType getLeft(); - - /** - * Get the value contained on the right of this bifunctor - * - * @return The value on the right of this bifunctor - */ - public RightType getRight(); -} +package bjc.utils.funcdata.theory; + +import java.util.function.Function; + +/** + * A functor over a pair of heterogeneous types + * + * @author ben + * @param + * The type stored on the 'left' of the pair + * @param + * The type stored on the 'right' of the pair + * + */ +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 + * + * @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 func + * The function to lift to work over the left side of the + * pair + * @return The function lifted to work over the left side of bifunctors + */ + public Function, Bifunctor> fmapLeft( + Function func); + + /** + * Lift a function to operate over the right part of this pair + * + * @param + * The old left type of the pair + * @param + * The old right type of the pair + * @param + * The new right type of the pair + * @param func + * The function to lift to work over the right side of + * the pair + * @return The function lifted to work over the right side of bifunctors + */ + public Function, Bifunctor> fmapRight( + Function func); + + /** + * Get the value contained on the left of this bifunctor + * + * @return The value on the left side of this bifunctor + */ + public LeftType getLeft(); + + /** + * Get the value contained on the right of this bifunctor + * + * @return The value on the right of this bifunctor + */ + public RightType getRight(); +} -- cgit v1.2.3