
fj.F2 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionaljava Show documentation
Show all versions of functionaljava Show documentation
Functional Java is an open source library that supports closures for the Java programming language
The newest version!
package fj;
import fj.control.parallel.Promise;
import fj.data.*;
import java.util.function.BiFunction;
import static fj.P.p;
import static fj.data.IterableW.wrap;
import static fj.data.Set.iterableSet;
import static fj.data.Tree.node;
import static fj.data.TreeZipper.treeZipper;
import static fj.data.Zipper.zipper;
/**
* A transformation function of arity-2 from A
and B
to C
.
*/
@FunctionalInterface
public interface F2 extends BiFunction {
/**
* Transform A
and B
to C
.
*
* @param a The A
to transform.
* @param b The B
to transform.
* @return The result of the transformation.
*/
C f(A a, B b);
default C apply(A a, B b) {
return f(a, b);
}
/**
* Partial application.
*
* @param a The A
to which to apply this function.
* @return The function partially applied to the given argument.
*/
default F f(final A a) {
return b -> f(a, b);
}
/**
* Curries this wrapped function to a wrapped function of arity-1 that returns another wrapped function.
*
* @return a wrapped function of arity-1 that returns another wrapped function.
*/
default F> curry() {
return a -> b -> f(a, b);
}
/**
* Flips the arguments of this function.
*
* @return A new function with the arguments of this function flipped.
*/
default F2 flip() {
return (b, a) -> f(a, b);
}
/**
* Uncurries this function to a function on tuples.
*
* @return A new function that calls this function with the elements of a given tuple.
*/
default F, C> tuple() {
return p -> f(p._1(), p._2());
}
/**
* Promotes this function to a function on Arrays.
*
* @return This function promoted to transform Arrays.
*/
default F2, Array, Array> arrayM() {
return (a, b) -> a.bind(b, curry());
}
/**
* Promotes this function to a function on Promises.
*
* @return This function promoted to transform Promises.
*/
default F2, Promise, Promise> promiseM() {
return (a, b) -> a.bind(b, curry());
}
/**
* Promotes this function to a function on Iterables.
*
* @return This function promoted to transform Iterables.
*/
default F2, Iterable, IterableW> iterableM() {
return (a, b) -> IterableW.liftM2(curry()).f(a).f(b);
}
/**
* Promotes this function to a function on Lists.
*
* @return This function promoted to transform Lists.
*/
default F2, List, List> listM() {
return (a, b) -> List.liftM2(curry()).f(a).f(b);
}
/**
* Promotes this function to a function on non-empty lists.
*
* @return This function promoted to transform non-empty lists.
*/
default F2, NonEmptyList, NonEmptyList> nelM() {
return (as, bs) -> NonEmptyList.fromList(as.toList().bind(bs.toList(), this)).some();
}
/**
* Promotes this function to a function on Options.
*
* @return This function promoted to transform Options.
*/
default F2
© 2015 - 2025 Weber Informatics LLC | Privacy Policy