summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-04-08 13:28:09 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-04-08 13:28:09 -0400
commit275a627719fc2231b16caea41130ff09f0f2b6a1 (patch)
tree757e8ca2061ba6ed9b2063f7155edbe954b72bdb /BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java
parent79d3a4a47cbc1fcf17c77c6fc12ff826a3077bac (diff)
Switch functional data to use interfaces
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java44
1 files changed, 44 insertions, 0 deletions
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 <A> The initial type of the function
+ * @param <B> The intermediate type of the function
+ * @param <C> 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 <A, B, C> Function<A, Function<B, C>> curry2(
+ BiFunction<A, B, C> func) {
+ return (arg1) -> (arg2) -> {
+ return func.apply(arg1, arg2);
+ };
+ }
+}