Package com.ontology2.pidove.util
Class Composer
java.lang.Object
com.ontology2.pidove.util.Composer
Many programming languages have a function for composing functions; here is an attempt to make the
most of the concept in Java.
One limitation here is that to take advantage of the strong typing in Java we have to generate a
large number of functions with different signatures.
The ideal grammar of compose is that the first argument is a Supplier, Function, or BiFunction. In
the middle there could be an arbitrary number of functions, at the end there either a Function,
Consumer, or Predicate. That gives 9 basic forms, and these could be extended to some length N
of intervening functions. A challenge with this idea is that a lambda function like
x -> -x
can be alternately be treated as a Consumer or a Function and one like
x -> x == 15
can be treated as as either a Function or a Predicate so for this to work we have to change the name
of the function.
To support, say N=10 this is a job for code generation.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A,
B, X, C> BiFunction<A, B, C> compose
(BiFunction<A, B, X> f1, Function<X, C> f2) static <A,
B, X> Function<A, B> static <A,
B, X1, X2>
Function<A,B> static <A,
B, X1, X2, X3>
Function<A,B> static <A,
B> Supplier<B> static <A,
B, X> BiPredicate<A, B> composePredicate
(BiFunction<A, B, X> f1, Predicate<X> f2) static <A,
B> Predicate<A> composePredicate
(Function<A, B> f1, Predicate<B> f2) Function<X,Boolean> is ambiguous with Predicate<X> so we need to change the name of this function so it doesn't conflict with ordinary compose.static <A,
B> Consumer<A> composeVoid
(Function<A, B> f1, Consumer<B> f2)
-
Constructor Details
-
Composer
public Composer()
-
-
Method Details
-
compose
-
compose
-
compose
-
compose
-
composeVoid
-
compose
-
composePredicate
Function<X,Boolean> is ambiguous with Predicate<X> so we need to change the name of this function so it doesn't conflict with ordinary compose.- Type Parameters:
A
- input typeB
- inner type of predicate- Parameters:
f1
- first functionf2
- second function, a predicate- Returns:
- true or false depending on predicate
-
composePredicate
-