diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-12-01 20:19:34 -0500 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-12-01 20:19:34 -0500 |
| commit | fefd6eb2917b9a0856c247353545cc13876b6eda (patch) | |
| tree | 374e2d31426accd3f00c6bbbff2ff75123d92da2 /base/src/main/java/bjc/utils/funcutils/FuncUtils.java | |
| parent | 03de62016afa4e392f32069ec28ad58ee38699da (diff) | |
An assortment of changes/new things
Diffstat (limited to 'base/src/main/java/bjc/utils/funcutils/FuncUtils.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/funcutils/FuncUtils.java | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/base/src/main/java/bjc/utils/funcutils/FuncUtils.java b/base/src/main/java/bjc/utils/funcutils/FuncUtils.java index 70e521a..2c65876 100644 --- a/base/src/main/java/bjc/utils/funcutils/FuncUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/FuncUtils.java @@ -29,9 +29,12 @@ public class FuncUtils { * * @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 -> 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); } /** @@ -43,14 +46,17 @@ public class FuncUtils { * @param cons * The action to perform. */ - public static void doTimes(final int nTimes, final Consumer<Integer> cons) { - for (int i = 0; i < nTimes; i++) { - cons.accept(i); - } + public static void doTimes( + final int nTimes, + final Consumer<Integer> cons) + { + for (int i = 0; i < nTimes; i++) cons.accept(i); } /** * Return an operator that executes until it converges. + * + * @param <T> The type the operator is on. * * @param op * The operator to execute. @@ -62,12 +68,15 @@ public class FuncUtils { * @return The requested operator. */ public static <T> UnaryOperator<T> converge(final UnaryOperator<T> op, - final int maxTries) { + final int maxTries) + { return converge(op, Object::equals, maxTries); } /** * Return an operator that executes until it converges. + * + * @param <T> The type the operator is on. * * @param op * The operator to execute. @@ -81,11 +90,14 @@ public class FuncUtils { * * @return The requested operator. */ - public static <T> UnaryOperator<T> converge(final UnaryOperator<T> op, - final BiPredicate<T, T> converged, final int maxTries) { + 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; + T oldVal = newVal; int tries = 0; |
