@FunctionalInterface public interface Function1<T,U> extends Function<T,U>, Consumer<T>
Modifier and Type | Interface and Description |
---|---|
static class |
Function1.BooleanCombiner |
static class |
Function1.Const |
static class |
Function1.ConstBool |
Modifier and Type | Field and Description |
---|---|
static Function1<Object,Boolean> |
ACCEPT
Deprecated.
|
static Function1<Object,Object> |
IDENTITY
Deprecated.
|
static Function1<Object,Boolean> |
REJECT
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
static <T> Function1<T,Boolean> |
accept()
Returns a type-safe version of the ConstBool.ACCEPT predicate.
|
default void |
accept(T t)
For compatibility with java.util.function.Consumer.
|
static <S> Function1<S,Boolean> |
and(Function1<S,Boolean> a,
Function1<S,Boolean> b) |
static <T> Function1<T,Boolean> |
and(Iterable<Function1<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> Function1<S,U> |
compose(Function1<? super S,? extends T> f) |
static <V> Function1<V,V> |
compose(Iterable<Function1<V,V>> in)
Composes multiple functions into a single function to potentially minimize trips through
the source data.
|
static <V> Function1<V,V> |
identity() |
static <A,B> Function1<A,B> |
memoize(Function1<A,B> f)
Use only on pure functions with no side effects.
|
static <S> Function1<S,Boolean> |
negate(Function1<? super S,Boolean> a) |
static <S> Function1<S,Boolean> |
or(Function1<S,Boolean> a,
Function1<S,Boolean> b) |
static <T> Function1<T,Boolean> |
or(Iterable<Function1<T,Boolean>> in)
Composes multiple predicates into a single predicate to potentially minimize trips through
the source data.
|
static <T> Function1<T,Boolean> |
reject()
Returns a type-safe version of the ConstBool.REJECT predicate.
|
@Deprecated static final Function1<Object,Object> IDENTITY
Function1.Const.IDENTITY
instead.@Deprecated static final Function1<Object,Boolean> ACCEPT
Function1.ConstBool.ACCEPT
instead@Deprecated static final Function1<Object,Boolean> REJECT
Function1.ConstBool.REJECT
insteadstatic <T> Function1<T,Boolean> accept()
static <T> Function1<T,Boolean> reject()
static <V> Function1<V,V> compose(Iterable<Function1<V,V>> in)
public static <A,B,C> Function1<A,C> chain2(final Function1<A,B> f1,
final Function1<B,C> f2) {
return new Function1<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> Function1<T,Boolean> and(Iterable<Function1<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> Function1<T,Boolean> or(Iterable<Function1<T,Boolean>> in)
T
- the type of object to predicate on.in
- the predicates to test in order. Nulls and ConstBool.REJECT predicates are ignored. Any
ACCEPT predicate will cause this entire method to return the ACCEPT predicate.
No predicates means ConstBool.REJECT.static <A,B> Function1<A,B> memoize(Function1<A,B> f)
U applyEx(T t) throws Exception
Exception
default U apply(T t)
default void accept(T t)
Copyright © 2016. All rights reserved.