See: Description
Interface | Description |
---|---|
Function0<U> |
This is like Java 8's java.util.function.Supplier, but retrofitted to turn checked exceptions
into unchecked ones.
|
Function1<T,U> |
This is like Java 8's java.util.function.Function, but retrofitted to turn checked exceptions
into unchecked ones.
|
Function2<A,B,R> |
This is like Java 8's java.util.function.BiFunction, but retrofitted to turn checked exceptions
into unchecked ones.
|
Function3<A,B,C,R> |
A three-argument, exception-safe functional interface.
|
Class | Description |
---|---|
Function0.Constant<K> |
Wraps a value in a constant function.
|
Enum | Description |
---|---|
Function0.Const | |
Function1.BooleanCombiner | |
Function1.Const | |
Function1.ConstBool |
Exception-friendly functional interfaces named by the number of arguments: Function0, Function1, Function2....
All of these have an applyEx()
method that that throws an Exception and returns a result.
Implementers should override the applyEx()
method (this happens automatically when you use Java 8's lambda syntax).
Each interface also has a default apply()
method for consumers of this function to call.
It re-throws all exceptions after wrapping any checked ones in unchecked RuntimeException
s.
For simplicity, there are no primitive versions of these functions, no "void" return types, and no special-purpose funny names.
If you don't want to return a result, declare the return type as ?
and return null.
Comparing just the Consumer interfaces from { @link java.util.function}:
java.util.function | org.organicdesign.fp.function |
---|---|
Consumer<T> | Function1<T,?> |
DoubleConsumer | Function1<Double,?> |
IntConsumer | Function1<Integer,?> |
LongConsumer | Function1<Long,?> |
BiConsumer<T,U> | Function2<T,U,?> |
ObjDoubleConsumer<T> | Function2<T,Double,?> |
ObjIntConsumer<T> | Function2<T,Integer,?> |
ObjLongConsumer<T> | Function2<T,Long,?> |
Copyright © 2017. All rights reserved.