diMapL and diMapR over this function in the same invocation.
*
- * @param lFn the contravariant argument mapping function
- * @param rFn the covariant result mapping function
* @param Fn2 in terms of Fn1 provides a
* reasonable approximation of currying in the form of multiple apply overloads that take different numbers
@@ -53,4 +55,14 @@ default Fn2 flip() {
default Fn1Fn2 as a j.u.f.BiFunction.
+ *
+ * @return the same logic as a BiFunction
+ * @see BiFunction
+ */
+ default BiFunction toBiFunction() {
+ return this::apply;
+ }
}
diff --git a/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/All.java b/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/All.java
index d3d96ccb4..c0a4f2cc7 100644
--- a/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/All.java
+++ b/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/All.java
@@ -3,6 +3,8 @@
import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functions.Fn2;
+import java.util.function.Function;
+
/**
* Eagerly apply a predicate to each element in an Iterable, returning true if every element
* satisfies the predicate, and false otherwise. This method short-circuits on the first false
@@ -11,13 +13,13 @@
* @param The input Iterable element type
* @see Any
*/
-public final class All implements Fn2Iterable, returning true if any element
* satisfies the predicate, and false otherwise. This method short-circuits on the first true
@@ -11,13 +13,13 @@
* @param The input Iterable element type
* @see All
*/
-public final class Any implements Fn2Iterable by skipping the first contiguous group of elements that satisfy the predicate,
* beginning iteration at the first element for which the predicate evaluates to false.
@@ -14,13 +16,13 @@
* @see TakeWhile
*/
-public final class DropWhile implements Fn2Iterable, returning an Iterable of just the
* elements for which the predicate evaluated to true.
@@ -12,13 +14,13 @@
* @see TakeWhile
* @see DropWhile
*/
-public final class Filter implements Fn2Iterable from the successive applications of the function first to the
@@ -15,25 +16,25 @@
*
* @param The Iterable element type
*/
-public final class Iterate implements Fn2Iterable, producing an Iterable of the mapped
* results.
@@ -11,13 +13,13 @@
* @param A type contravariant to the input Iterable element type
* @param A type covariant to the output Iterable element type
*/
-public final class Map implements Fn2Fn2, producing a Fn1 that takes the remaining
- * argument. This is isomorphic to calling {@link Fn2#apply(Object)}.
+ * Partially apply (fix) the first argument of a {@link BiFunction}, producing an Fn1 that
+ * takes the remaining argument. This is isomorphic to calling {@link Fn2#apply(Object)}.
*
* @param The type of the value to be supplied
* @param The input argument type of the resulting function
* @param Iterable of As and a {@link Fn2}<A, A, A>, iteratively
+ * Given an Iterable of As and a {@link BiFunction}<A, A, A>, iteratively
* accumulate over the Iterable, returning an Optional<A> (if the Iterable
* is empty, the result is Optional.empty(); otherwise, the result is wrapped in
* Optional.of(). For this reason, null accumulation results are considered erroneous and will
@@ -22,13 +23,13 @@
* @see ReduceRight
* @see com.jnape.palatable.lambda.functions.builtin.fn3.FoldLeft
*/
-public final class ReduceLeft implements Fn2Iterable of As and a {@link Fn2}<A, A, A>, iteratively
+ * Given an Iterable of As and a {@link BiFunction}<A, A, A>, iteratively
* accumulate over the Iterable, returning an Optional<A> (if the Iterable
* is empty, the result is Optional.empty(); otherwise, the result is wrapped in
* Optional.of(). For this reason, null accumulation results are considered erroneous and will
@@ -22,25 +23,25 @@
* @see ReduceLeft
* @see com.jnape.palatable.lambda.functions.builtin.fn3.FoldRight
*/
-public final class ReduceRight implements Fn2Iterable to the first group of contiguous elements that satisfy the predicate by
* iterating up to, but not including, the first element for which the predicate evaluates to false.
@@ -13,13 +15,13 @@
* @see Filter
* @see DropWhile
*/
-public final class TakeWhile implements Fn2Optional<{@link
@@ -28,13 +29,13 @@
* @param The output Iterable element type
* @param The unfolding function input type
*/
-public final class Unfoldr implements Fn2>>, B, Iterable> {
+public final class Unfoldr implements Fn2>>, B, Iterable> {
private Unfoldr() {
}
@Override
- public Iterable apply(Fn1>> fn, B b) {
+ public Iterable apply(Function>> fn, B b) {
return () -> new UnfoldingIterator<>(fn, b);
}
@@ -42,11 +43,11 @@ public static Unfoldr unfoldr() {
return new Unfoldr<>();
}
- public static Fn1> unfoldr(Fn1>> fn) {
+ public static Fn1> unfoldr(Function>> fn) {
return Unfoldr.unfoldr().apply(fn);
}
- public static Iterable unfoldr(Fn1>> fn, B b) {
+ public static Iterable unfoldr(Function>> fn, B b) {
return unfoldr(fn).apply(b);
}
}
diff --git a/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/Zip.java b/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/Zip.java
index 1cc8838ca..b9ae36cf6 100644
--- a/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/Zip.java
+++ b/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/Zip.java
@@ -4,7 +4,6 @@
import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functions.Fn2;
-import static com.jnape.palatable.lambda.functions.builtin.fn2.Tupler2.tupler;
import static com.jnape.palatable.lambda.functions.builtin.fn3.ZipWith.zipWith;
/**
@@ -23,7 +22,7 @@ private Zip() {
@Override
public Iterable> apply(Iterable as, Iterable bs) {
- return zipWith(tupler(), as, bs);
+ return zipWith(Tupler2.tupler().toBiFunction(), as, bs);
}
public static Zip zip() {
diff --git a/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn3/FoldLeft.java b/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn3/FoldLeft.java
index 97f5a658c..a64e099ae 100644
--- a/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn3/FoldLeft.java
+++ b/src/main/java/com/jnape/palatable/lambda/functions/builtin/fn3/FoldLeft.java
@@ -4,12 +4,14 @@
import com.jnape.palatable.lambda.functions.Fn2;
import com.jnape.palatable.lambda.functions.Fn3;
+import java.util.function.BiFunction;
+
/**
- * Given an Iterable of As, a starting value B, and a {@link Fn2}<B, A,
- * B>, iteratively accumulate over the Iterable, ultimately returning a final B
- * value. If the Iterable is empty, just return the starting B value. Note that, as the name
- * implies, this function accumulates from left to right, such that foldLeft(f, 0, asList(1, 2, 3, 4, 5))
- * is evaluated as f(f(f(f(f(0, 1), 2), 3), 4), 5).
+ * Given an Iterable of As, a starting value B, and a {@link
+ * BiFunction}<B, A, B>, iteratively accumulate over the Iterable, ultimately returning a
+ * final B value. If the Iterable is empty, just return the starting B value.
+ * Note that, as the name implies, this function accumulates from left to right, such that foldLeft(f, 0,
+ * asList(1, 2, 3, 4, 5)) is evaluated as f(f(f(f(f(0, 1), 2), 3), 4), 5).
*
* For more information, read about Catamorphisms.
@@ -18,13 +20,13 @@
* @param The accumulation type
* @see FoldRight
*/
-public final class FoldLeft implements Fn3, B, Iterable, B> {
+public final class FoldLeft implements Fn3, B, Iterable, B> {
private FoldLeft() {
}
@Override
- public B apply(Fn2 super B, ? super A, ? extends B> fn, B acc, Iterable as) {
+ public B apply(BiFunction super B, ? super A, ? extends B> fn, B acc, Iterable as) {
B accumulation = acc;
for (A a : as)
accumulation = fn.apply(accumulation, a);
@@ -35,15 +37,15 @@ public static FoldLeft foldLeft() {
return new FoldLeft<>();
}
- public static Fn2, B> foldLeft(Fn2 super B, ? super A, ? extends B> fn) {
+ public static