From 275a627719fc2231b16caea41130ff09f0f2b6a1 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Fri, 8 Apr 2016 13:28:09 -0400 Subject: Switch functional data to use interfaces --- .../main/java/bjc/utils/funcutils/FuncUtils.java | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java new file mode 100644 index 0000000..d89b7da --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java @@ -0,0 +1,44 @@ +package bjc.utils.funcutils; + +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.IntConsumer; + +/** + * Utility things for functions + * + * @author ben + * + */ +public class FuncUtils { + /** + * Do the specified action the specified number of times + * + * @param nTimes + * The number of times to do the action + * @param cons + * The action to perform + */ + public static void doTimes(int nTimes, IntConsumer cons) { + for (int i = 0; i < nTimes; i++) { + cons.accept(i); + } + } + + /** + * Convert a binary function into a unary function that returns a + * function + * + * @param The initial type of the function + * @param The intermediate type of the function + * @param The terminal type of the function + * @param func The function to transform + * @return The function transformed into a unary function returning a function + */ + public static Function> curry2( + BiFunction func) { + return (arg1) -> (arg2) -> { + return func.apply(arg1, arg2); + }; + } +} -- cgit v1.2.3