Package org.organicdesign.fp.function
Interface Fn2<A,B,R>
-
- All Superinterfaces:
BiFunction<A,B,R>
- All Known Implementing Classes:
Fn2.Singletons
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Fn2<A,B,R> extends BiFunction<A,B,R>
This is like Java 8's java.util.function.BiFunction, but retrofitted to turn checked exceptions into unchecked ones.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Fn2.Singletons
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default R
apply(A a, B b)
The class that takes a consumer as an argument uses this convenience method so that it doesn't have to worry about checked exceptions either.R
applyEx(A a, B b)
Implement this one method and you don't have to worry about checked exceptions.static <A1,B1>
Fn2<A1,? super B1,A1>first()
Returns a static function that always returns the first argument it is given.static <A,B,Z>
Fn2<A,B,Z>memoize(Fn2<A,B,Z> f)
Use only on pure functions with no side effects.static <A1,B1>
Fn2<A1,? super B1,B1>second()
Returns a static function that always returns the second argument it is given.-
Methods inherited from interface java.util.function.BiFunction
andThen
-
-
-
-
Method Detail
-
applyEx
R applyEx(A a, B b) throws Exception
Implement this one method and you don't have to worry about checked exceptions.- Throws:
Exception
-
apply
default R apply(A a, B b)
The class that takes a consumer as an argument uses this convenience method so that it doesn't have to worry about checked exceptions either.- Specified by:
apply
in interfaceBiFunction<A,B,R>
-
memoize
static <A,B,Z> Fn2<A,B,Z> memoize(Fn2<A,B,Z> f)
Use only on pure functions with no side effects. Wrap an expensive function with this and for each input value, the output will only be computed once. Subsequent calls with the same input will return identical output very quickly. Please note that the parameters to f need to implement equals() and hashCode() correctly for this to work correctly and quickly.
-
first
static <A1,B1> Fn2<A1,? super B1,A1> first()
Returns a static function that always returns the first argument it is given.- Returns:
- the first argument, unmodified.
-
second
static <A1,B1> Fn2<A1,? super B1,B1> second()
Returns a static function that always returns the second argument it is given.- Returns:
- the second argument, unmodified.
-
-