# Package de.caff.generics.function

Function support.

See: Description

- Interface Summary
  Interface | Description
  --- | ---
  BooleanConsumer | A consumer for short values.
  BooleanFunction1<T> | Function which has a primitive boolean as input, and an object as output.
  BooleanFunction2<T> | Function which has two primitive booleans as input, and an object as output.
  BooleanOperator0 | Function with no argument and a boolean result.
  BooleanOperator1 | Unary operator with a boolean argument and result.
  BooleanOperator2 | Binary operator with two boolean arguments and a boolean result.
  BooleanOperator3 | Ternary operator with three boolean arguments and a boolean result.
  BooleanPredicate1 | Predicate which expects a primitive boolean argument.
  BooleanPredicate2 | Predicate which expects two primitive boolean arguments.
  BooleanPredicate3 | Predicate which expects three primitive boolean arguments.
  BooleanSetter<T> | Procedure with a generic and a boolean argument.
  ByteConsumer | A consumer for short values.
  ByteFunction1<T> | Function which has a primitive byte as input, and an object as output.
  ByteFunction2<T> | Function which has two primitive bytes as input, and an object as output.
  ByteOperator0 | Function with no argument and a byte result.
  ByteOperator1 | Unaray operator with a byte argument and result.
  ByteOperator2 | Binary operator with two byte arguments and a byte result.
  ByteOperator3 | Ternary operator with three byte arguments and a byte result.
  ByteOrdering | Define an order for two primitive byte values.
  ByteOrdering.Serial | A byte ordering which is serializable.
  BytePredicate1 | Predicate which expects a primitive byte argument.
  BytePredicate2 | Predicate which expects two primitive byte arguments.
  BytePredicate3 | Predicate which expects three primitive byte arguments.
  ByteSetter<T> | Procedure with a generic and a byte argument.
  CharConsumer | A consumer for short values.
  CharFunction1<T> | Function which has a primitive character as input, and an object as output.
  CharFunction2<T> | Function which has two primitive characters as input, and an object as output.
  CharOperator0 | Function with no argument and a char result.
  CharOperator1 | Unary operator with a char argument and result.
  CharOperator2 | Binary operator with two char arguments and a char result.
  CharOperator3 | Ternary operator with three char arguments and a char result.
  CharOrdering | Define an order for two primitive char values.
  CharOrdering.Serial | A char ordering which is serializable.
  CharPredicate1 | Predicate which expects a primitive char argument.
  CharPredicate2 | Predicate which expects two primitive char arguments.
  CharPredicate3 | Predicate which expects three primitive char arguments.
  CharSetter<T> | Procedure with a generic and a char argument.
  DoubleFunction2<T> | Function with 2 primitive double arguments creation a general result.
  DoubleFunction3<T> | Function with 3 primitive double arguments creation a general result.
  DoubleFunction4<T> | Function with 4 primitive double arguments creation a general result.
  DoubleOperator0 | Function with no argument and a double result.
  DoubleOperator1 | Unary operator with a double argument and result.
  DoubleOperator2 | Binary operator with two double arguments and a double result.
  DoubleOperator3 | Ternary operator with three double arguments and a double result.
  DoubleOrdering | Define an order for two primitive double values.
  DoubleOrdering.Serial | A double ordering which is serializable.
  DoublePredicate1 | Predicate which expects a primitive double argument.
  DoublePredicate2 | Predicate which expects two primitive double arguments.
  DoublePredicate3 | Predicate which expects three primitive double arguments.
  DoubleSetter<T> | Procedure with a generic and a double argument.
  FloatConsumer | A consumer for short values.
  FloatFunction1<T> | Function which has a primitive float as input, and an object as output.
  FloatFunction2<T> | Function which has two primitive floats as input, and an object as output.
  FloatOperator0 | Function with no argument and a float result.
  FloatOperator1 | Unary operator with a float argument and result.
  FloatOperator2 | Binary operator with two float arguments and a float result.
  FloatOperator3 | Ternary operator with three float arguments and a float result.
  FloatOrdering | Define an order for two primitive float values.
  FloatOrdering.Serial | A float ordering which is serializable.
  FloatPredicate1 | Predicate which expects a primitive float argument.
  FloatPredicate2 | Predicate which expects two primitive float arguments.
  FloatPredicate3 | Predicate which expects three primitive float arguments.
  FloatSetter<T> | Procedure with a generic and a float argument.
  FragileBooleanConsumer<E extends java.lang.Exception> | Boolean consumer which throws a checked exception.
  FragileByteConsumer<E extends java.lang.Exception> | Byte consumer which throws a checked exception.
  FragileCharConsumer<E extends java.lang.Exception> | Character consumer which throws a checked exception.
  FragileDoubleConsumer<E extends java.lang.Exception> | Double consumer which throws a checked exception.
  FragileFloatConsumer<E extends java.lang.Exception> | Float consumer which throws a checked exception.
  FragileFunction0<R,E extends java.lang.Exception> | Function with no parameter which can throw an exception.
  FragileFunction1<R,E extends java.lang.Exception,P> | Function with one parameter, possibly throwing an exception.
  FragileFunction2<R,E extends java.lang.Exception,P1,P2> | Function with two parameters, possibly throwing an exception.
  FragileFunction3<R,E extends java.lang.Exception,P1,P2,P3> | Function with three parameters, possibly throwing a checked exception.
  FragileFunction4<R,E extends java.lang.Exception,P1,P2,P3,P4> | Function with four parameters, possibly throwing a checked exception.
  FragileIntConsumer<E extends java.lang.Exception> | Int consumer which throws a checked exception.
  FragileLongConsumer<E extends java.lang.Exception> | Long consumer which throws a checked exception.
  FragilePredicate1<E extends java.lang.Exception,P> | A function with one argument which returns a boolean value, and throws a checked exception.
  FragilePredicate2<E extends java.lang.Exception,P1,P2> | A function with two arguments which returns a boolean value, and might throw a checked exception.
  FragileProcedure0<E extends java.lang.Exception> | Function without return and with no paramete, but a possible expectionr.
  FragileProcedure1<E extends java.lang.Exception,P> | Function without return and with one parameter.
  FragileProcedure2<E extends java.lang.Exception,P1,P2> | Function without return and with two parameters.
  FragileProcedure3<E extends java.lang.Exception,P1,P2,P3> | Function without return and with three parameters.
  FragileProcedure4<E extends java.lang.Exception,P1,P2,P3,P4> | Function without return and with four parameters.
  FragileShortConsumer<E extends java.lang.Exception> | Short consumer which throws a checked exception.
  Function0<R> | Function with no parameter.
  Function1<R,P> | Function with one parameter.
  Function2<R,P1,P2> | Function with two parameters.
  Function3<R,P1,P2,P3> | Function with three parameters.
  Function4<R,P1,P2,P3,P4> | Function with four parameters.
  Function5<R,P1,P2,P3,P4,P5> | Function with five parameters.
  Function6<R,P1,P2,P3,P4,P5,P6> | Function with six parameters.
  Function7<R,P1,P2,P3,P4,P5,P6,P7> | Function with seven parameters.
  Function8<R,P1,P2,P3,P4,P5,P6,P7,P8> | Function with eight parameters.
  Function9<R,P1,P2,P3,P4,P5,P6,P7,P8,P9> | Function with nine parameters.
  IntFunction2<T> | Function with two integer arguments and generic result.
  IntFunction3<T> | Function with three integer arguments and generic result.
  IntOperator0 | Function with no argument and an int result.
  IntOperator1 | Unary operator with a int argument and result.
  IntOperator2 | Binary operator with two int arguments and a int result.
  IntOperator3 | Ternary operator with three int arguments and a int result.
  IntOrdering | Define an order for two primitive int values.
  IntOrdering.Serial | An int ordering which is serializable.
  IntPredicate1 | Predicate which expects a primitive integer argument.
  IntPredicate2 | Predicate which expects two primitive integer arguments.
  IntPredicate3 | Predicate which expects three primitive integer arguments.
  IntSetter<T> | Procedure with a generic and a int argument.
  IntToByteFunction1 | Function with one primitive integer argument and a primitive byte return.
  IntToByteFunction2 | Function with two primitive integer arguments and a primitive byte result.
  IntToByteFunction3 | Function with three primitive integer arguments and a primitive byte result.
  IntToCharFunction1 | Function with one primitive integer argument and a primitive char return.
  IntToCharFunction2 | Function with two primitive integer arguments and a primitive byte result.
  IntToCharFunction3 | Function with three primitive integer arguments and a primitive char result.
  IntToDoubleFunction2 | Function with two primitive integer arguments and a primitive double result.
  IntToDoubleFunction3 | Function with three primitive integer arguments and a primitive double result.
  IntToFloatFunction1 | Function with one primitive integer argument and a primitive flaat return.
  IntToFloatFunction2 | Function with two primitive integer arguments and a primitive float result.
  IntToFloatFunction3 | Function with three primitive integer arguments and a primitive float result.
  IntToIntFunction3 | Function with three primitive integer arguments and a primitive integer result.
  IntToLongFunction2 | Function with two primitive integer arguments and a primitive long result.
  IntToLongFunction3 | Function with three primitive integer arguments and a primitive long result.
  IntToShortFunction1 | Function with one primitive integer argument and a primitive short return.
  IntToShortFunction2 | Function with two primitive integer arguments and a primitive short result.
  IntToShortFunction3 | Function with three primitive integer arguments and a primitive short result.
  LongFunction2<T> | Function which has two primitive longs as input, and an object as output.
  LongOperator0 | Function with no argument and a long result.
  LongOperator1 | Unary operator with a long argument and result.
  LongOperator2 | Binary operator with two long arguments and a long result.
  LongOperator3 | Function with three long arguments and a long result.
  LongOrdering | Define an order for two primitive long values.
  LongOrdering.Serial | A long ordering which is serializable.
  LongPredicate1 | Predicate which expects a primitive long argument.
  LongPredicate2 | Predicate which expects two primitive long arguments.
  LongPredicate3 | Predicate which expects three primitive long arguments.
  LongSetter<T> | Procedure with a generic and a long argument.
  Ordering<T> | Define an order for two objects of a generic type.
  Ordering.Serial<E> | An ordering which is serializable.
  Predicate1<P> | A function with one argument which returns a boolean value.
  Predicate2<P1,P2> | A function with two arguments which returns a boolean value.
  Predicate3<P1,P2,P3> | A function with three arguments which returns a boolean value.
  Predicate4<P1,P2,P3,P4> | A function with four arguments which returns a boolean value.
  Predicate5<P1,P2,P3,P4,P5> | A function with five arguments which returns a boolean value.
  Predicate6<P1,P2,P3,P4,P5,P6> | A function with six arguments which returns a boolean value.
  Predicate7<P1,P2,P3,P4,P5,P6,P7> | A function with seven arguments which returns a boolean value.
  Predicate8<P1,P2,P3,P4,P5,P6,P7,P8> | A function with eight arguments which returns a boolean value.
  Predicate9<P1,P2,P3,P4,P5,P6,P7,P8,P9> | A function with nine arguments which returns a boolean value.
  Procedure0 | Function without return and with no parameter.
  Procedure1<P> | Function without return and with one parameter.
  Procedure2<P1,P2> | Function without return and with two parameters.
  Procedure3<P1,P2,P3> | Function without return and with three parameters.
  Procedure4<P1,P2,P3,P4> | Function without return and with four parameters.
  Procedure5<P1,P2,P3,P4,P5> | Function without return and with five parameters.
  Procedure6<P1,P2,P3,P4,P5,P6> | Function without return and with six parameters.
  Procedure7<P1,P2,P3,P4,P5,P6,P7> | Function without return and with seven parameters.
  Procedure8<P1,P2,P3,P4,P5,P6,P7,P8> | Function without return and with eight parameters.
  Procedure9<P1,P2,P3,P4,P5,P6,P7,P8,P9> | Function without return and with nine parameters.
  ShortConsumer | A consumer for short values.
  ShortFunction1<T> | Function which has a primitive short as input, and an object as output.
  ShortFunction2<T> | Function which has two primitive shorts as input, and an object as output.
  ShortOperator0 | Function with no argument and a short result.
  ShortOperator1 | Unary operator with a short argument and result.
  ShortOperator2 | Binary operator with two short arguments and a short result.
  ShortOperator3 | Ternary operator with three short arguments and a short result.
  ShortOrdering | Define an order for two primitive short values.
  ShortOrdering.Serial | A short ordering which is serializable.
  ShortPredicate1 | Predicate which expects a primitive short argument.
  ShortPredicate2 | Predicate which expects two primitive short arguments.
  ShortPredicate3 | Predicate which expects three primitive short arguments.
  ShortSetter<T> | Procedure with a generic and a short argument.
  ToByteFunction<T> | A function which produces a byte value from a generic value.
  ToCharFunction<T> | A function which produces a char value from a generic value.
  ToFloatFunction<T> | A function which produces a float value from a generic value.
  ToShortFunction<T> | A function which produces a short value from a generic value.
  VarBooleanOperator | Primitive boolean operator with a variable number of arguments.
  VarByteOperator | Primitive byte operator with a variable number of arguments.
  VarCharOperator | Primitive char operator with a variable number of arguments.
  VarDoubleOperator | Primitive double operator with a variable number of arguments.
  VarFloatOperator | Primitive float operator with a variable number of arguments.
  VarIntOperator | Primitive integer operator with a variable number of arguments.
  VarLongOperator | Primitive long operator with a variable number of arguments.
  VarShortOperator | Primitive short operator with a variable number of arguments.

- Class Summary
  Class | Description
  --- | ---
  Predicates | Helper for predicates.

- Exception Summary
  Exception | Description
  --- | ---
  EvaluationException | Helper exception for wrapping a checked exception.

## Package de.caff.generics.function Description

Function support.

## General

- Interfaces with more than one argument provide default methods for partial evaluation.
- Generic functions, procedures (consumers) and predicates with more than one argument are also defined as 1-argument equivalents which accept a tuple. The tuple is expanded into the expected arguments in order one-by-one. So the tuple's size has to match the number of parameters, and the tuple's types have to match the parameter types.

## 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.

- `Function0`: function without argumen like `java.util.function.Supplier`.
- `Function1`: function with one argument like `java.util.function.Function`.
- `Function2`: function with two arguments like `java.util.function.BiFunction`.
- `Function3`: function with three arguments.
- `Function4`: function with four arguments.
- `Function5`: function with five arguments.
- `Function6`: function with six arguments.
- `Function7`: function with seven arguments.
- `Function8`: function with eight arguments.
- `Function9`: function with nine arguments.

## 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.

- `Procedure0`: procedure without argument.
- `Procedure1`: procedure with one argument.
- `Procedure2`: procedure with two arguments.
- `Procedure3`: procedure with three arguments.
- `Procedure4`: procedure with four arguments.
- `Procedure5`: procedure with five arguments.
- `Procedure6`: procedure with six arguments.
- `Procedure7`: procedure with seven arguments.
- `Procedure8`: procedure with eight arguments.
- `Procedure9`: procedure with nine arguments.

## 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.

- `Predicate1`: predicate with one argument.
- `Predicate2`: predicate with one arguments.
- `Predicate3`: predicate with three arguments.
- `Predicate4`: predicate with four arguments.
- `Predicate5`: predicate with five arguments.
- `Predicate6`: predicate with six arguments.
- `Predicate7`: predicate with seven arguments.
- `Predicate8`: predicate with eight arguments.
- `Predicate9`: predicate with nine arguments.

## 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.

- `FragileFunction0`: fragile function without arguments.
- `FragileFunction1`: fragile function with one arguments.

## 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

- Consumers: 1-argument procedure accepting the type, standard Java has thes only for `int`, `long`, and `double`.
- Functions: these accept 2 to 3 arguments of the given type, and return a non-primitive type. The 1-argument case is often already contained in the standard Java library, if not it is also provided here.
- Operators: these are functions which accept 0 to 3 arguments of the given type and return the same type.
- Predicates: these are functions which accept 1 or 2 arguments of the given type and return a `boolean`.

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`