Skip navigation links

Package de.caff.generics.function

Function support.

See: Description

Package de.caff.generics.function Description

Function support.

General

Simple Functions

Functions here take up to 9 arguments, and return one result. For historical reasons (this lib started earlier) the order of type arguments is different from standard Java Function and BiFunction. While Java orders the types like lambda arguments (<P1, P2, R>):

  (P1 arg1, P2 arg2) -> R
 
this lib follows the order in function definitions (<R, P1, P2>}:
  R function(P1 arg1, P2 arg2)  
 

Some of the functions are available in standard Java, and implementations here extend the standard interfaces nowadays, but usually come with a bit of benefit. But especially they allow more than 2 arguments.

Functions with 2 or more arguments can be chained after any function returning a tuple of the correct size and matching elements. See eg Function2.after3(de.caff.generics.function.Function3). Having the analogue to Function2.andThen(java.util.function.Function) is not possible due to the restrictions of the Java generic type system.

Procedures

Procedures are functions with no return values, so they are quite similar to functions:

As functions they can be chain after functions which return tuples of the correct size.

Predicates

Predicates are just functions which return a boolean. Basically a function returning a java.lang.Boolean is quite the same, but for one thing the predicates avoid boxing/unboxing, and come with special methods allowing easy boolean combination.

As functions they can be chain after functions which return tuples of the correct size.

Fragile functions

Fragile functions are like standard functions, but can throw exceptions. This concept is a bit fragile itself, so not supported as well as the above.

Operators, Functions and Consumers for Primitive Types

Some of these are lacking in the standard lib, although they are useful to avoid unnecessary boxing/unboxing.

Primitive types are divided in

Interface boolean byte char double float int long short
Consumer BooleanConsumer ByteConsumer CharConsumer java.util.function.DoubleConsumer BooleanConsumer java.util.function.IntConsumer java.util.function.LongConsumer ShortConsumer
Supplier (0-argument Operator) BooleanOperator0 ByteOperator0 CharOperator0 java.util.function.DoubleSupplier FloatOperator0 java.util.function.IntSupplier java.util.function.LongSupplier ShortOperator0
Unary (1-argument) Operator BooleanOperator1 ByteOperator1 CharOperator1 java.util.function.DoubleUnaryOperator FloatOperator1 java.util.function.IntUnaryOperator java.util.function.LongUnaryOperator ShortOperator1
Binary (2-argument) Operator BooleanOperator2 ByteOperator2 CharOperator2 java.util.function.DoubleBinaryOperator FloatOperator2 java.util.function.IntBinaryOperator java.util.function.LongBinaryOperator ShortOperator2
Ternary (3-argument) Operator BooleanOperator3 ByteOperator3 CharOperator3 DoubleOperator3 FloatOperator3 IntOperator3 LongOperator3 ShortOperator3
Variable Arguments Operator VarBooleanOperator VarByteOperator VarCharOperator VarDoubleOperator VarFloatOperator VarIntOperator VarLongOperator VarShortOperator
1-argument Predicate BooleanPredicate1 BytePredicate1 CharPredicate1 CharPredicate1 CharPredicate1 CharPredicate1 CharPredicate1 CharPredicate1
2-argument Predicate BooleanPredicate2 BytePredicate2 CharPredicate2 CharPredicate2 CharPredicate2 CharPredicate2 CharPredicate2 CharPredicate2
3-argument Predicate BooleanPredicate3 BytePredicate3 CharPredicate3 CharPredicate3 CharPredicate3 CharPredicate3 CharPredicate3 CharPredicate3
Skip navigation links