@FunctionalInterface public interface Fn1<T,U> extends Function<T,U>, Consumer<T>
Modifier and Type | Interface and Description |
---|---|
static class |
Fn1.BooleanCombiner |
static class |
Fn1.ConstObjBool
Constant functions that take an Object and return a Boolean
|
static class |
Fn1.ConstObjObj
Constant functions that take an Object and return an Object
|
Modifier and Type | Method and Description |
---|---|
static <T> Fn1<T,Boolean> |
accept()
Returns a type-safe version of the ConstObjBool.ACCEPT predicate.
|
default void |
accept(T t)
For compatibility with java.util.function.Consumer.
|
static <S> Fn1<S,Boolean> |
and(Fn1<S,Boolean> a,
Fn1<S,Boolean> b) |
static <T> Fn1<T,Boolean> |
and(Iterable<Fn1<T,Boolean>> in)
Composes multiple predicates into a single predicate to potentially minimize trips through
the source data.
|
default U |
apply(T t)
Call this convenience method so that you don't have to worry about checked exceptions.
|
U |
applyEx(T t)
Implement this one method and you don't have to worry about checked exceptions.
|
default <S> Fn1<S,U> |
compose(Fn1<? super S,? extends T> f) |
static <V> Fn1<V,V> |
compose(Iterable<Fn1<V,V>> in)
Composes multiple functions into a single function to potentially minimize trips through
the source data.
|
static <V> Fn1<V,V> |
identity() |
static <A,B> Fn1<A,B> |
memoize(Fn1<A,B> f)
Use only on pure functions with no side effects.
|
static <S> Fn1<S,Boolean> |
negate(Fn1<? super S,Boolean> a) |
static <S> Fn1<S,Boolean> |
or(Fn1<S,Boolean> a,
Fn1<S,Boolean> b) |
static <T> Fn1<T,Boolean> |
or(Iterable<Fn1<T,Boolean>> in)
Composes multiple predicates into a single predicate to potentially minimize trips through
the source data.
|
static <T> Fn1<T,Boolean> |
reject()
Returns a type-safe version of the ConstObjBool.REJECT predicate.
|
static <T> Fn1<T,Boolean> accept()
static <T> Fn1<T,Boolean> reject()
static <V> Fn1<V,V> compose(Iterable<Fn1<V,V>> in)
public static <A,B,C> Fn1<A,C> chain2(final Fn1<A,B> f1,
final Fn1<B,C> f2) {
return new Fn1<A,C>() {
@Override
public C applyEx(A a) throws Exception {
return f2.applyEx(f1.applyEx(a));
}
};
}
Even with 2 arguments, there are several signatures that would work: imagine where A=B, B=C,
or A=C. I just don't see the value to providing a bunch of chain2(), chain3() etc. functions
that will ultimately not be type-safe and cannot perform optimizations for you, when you can
roll your own type safe versions as you need them. Only the simplest case seems worth
providing, along the lines of the and() helper function in Filter()V
- the type of object to chain functions onin
- the functions to applyEx in order. Nulls and IDENTITY functions are ignored.
No functions means IDENTITY.static <T> Fn1<T,Boolean> and(Iterable<Fn1<T,Boolean>> in)
T
- the type of object to predicate on.in
- the predicates to test in order. Nulls and ACCEPT predicates are ignored. Any
REJECT predicate will cause this entire method to return a single REJECT predicate. No
predicates means ACCEPT.static <T> Fn1<T,Boolean> or(Iterable<Fn1<T,Boolean>> in)
T
- the type of object to predicate on.in
- the predicates to test in order. Nulls and ConstObjBool.REJECT predicates are ignored. Any
ACCEPT predicate will cause this entire method to return the ACCEPT predicate.
No predicates means ConstObjBool.REJECT.static <A,B> Fn1<A,B> memoize(Fn1<A,B> f)
U applyEx(T t) throws Exception
Exception
default U apply(T t)
default void accept(T t)
Copyright © 2017. All rights reserved.