diff options
Diffstat (limited to 'base/src/main/java/bjc/utils/funcutils/FuncUtils.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/funcutils/FuncUtils.java | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/base/src/main/java/bjc/utils/funcutils/FuncUtils.java b/base/src/main/java/bjc/utils/funcutils/FuncUtils.java index ff9fefb..70e521a 100644 --- a/base/src/main/java/bjc/utils/funcutils/FuncUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/FuncUtils.java @@ -13,38 +13,35 @@ import java.util.function.UnaryOperator; */ public class FuncUtils { /** - * Convert a binary function into a unary function that returns a - * function. + * Convert a binary function into a unary function that returns a function. * * @param <A> - * The initial type of the function. + * The initial type of the function. * * @param <B> - * The intermediate type of the function. + * The intermediate type of the function. * * @param <C> - * The terminal type of the function. + * The terminal type of the function. * * @param func - * The function to transform. + * The function to transform. * - * @return The function transformed into a unary function returning a - * function. + * @return The function transformed into a unary function returning a function. */ - public static <A, B, C> Function<A, Function<B, C>> curry2(final BiFunction<A, B, C> func) { - return arg1 -> arg2 -> { - return func.apply(arg1, arg2); - }; + public static <A, B, C> Function<A, Function<B, C>> + curry2(final BiFunction<A, B, C> func) { + return arg1 -> arg2 -> func.apply(arg1, arg2); } /** * Do the specified action the specified number of times. * * @param nTimes - * The number of times to do the action. + * The number of times to do the action. * * @param cons - * The action to perform. + * The action to perform. */ public static void doTimes(final int nTimes, final Consumer<Integer> cons) { for (int i = 0; i < nTimes; i++) { @@ -56,36 +53,37 @@ public class FuncUtils { * Return an operator that executes until it converges. * * @param op - * The operator to execute. + * The operator to execute. * * @param maxTries - * The maximum amount of times to apply the function in - * an attempt to cause it to converge. - * + * The maximum amount of times to apply the function in an + * attempt to cause it to converge. + * * @return The requested operator. */ - public static <T> UnaryOperator<T> converge(final UnaryOperator<T> op, final int maxTries) { - return converge(op, (nw, old) -> nw.equals(old), maxTries); + public static <T> UnaryOperator<T> converge(final UnaryOperator<T> op, + final int maxTries) { + return converge(op, Object::equals, maxTries); } /** * Return an operator that executes until it converges. * * @param op - * The operator to execute. + * The operator to execute. * @param converged - * The predicate to execute to check if the function has - * converged. + * The predicate to execute to check if the function has + * converged. * * @param maxTries - * The maximum amount of times to apply the function in - * an attempt to cause it to converge. - * + * The maximum amount of times to apply the function in an + * attempt to cause it to converge. + * * @return The requested operator. */ - public static <T> UnaryOperator<T> converge(final UnaryOperator<T> op, final BiPredicate<T, T> converged, - final int maxTries) { - return (val) -> { + public static <T> UnaryOperator<T> converge(final UnaryOperator<T> op, + final BiPredicate<T, T> converged, final int maxTries) { + return val -> { T newVal = op.apply(val); T oldVal; |
