Package de.scravy.bedrock
Class Functions
java.lang.Object
de.scravy.bedrock.Functions
public class Functions extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFunctions.ToBooleanBiFunction<A,B> -
Constructor Summary
Constructors Constructor Description Functions() -
Method Summary
Modifier and Type Method Description static <T> Predicate<T>and(Predicate<? extends T>... ps)Combines many predicates into a predicate that accepts its input only if it passes all predicates.static <A, B, R> Rapply(A arg1, B arg2, BiFunction<A,B,R> f)static <A, R> Rapply(A arg, Function<A,R> f)static <A, B, R> Function<B,R>bind(BiFunction<A,B,R> f, A a)static DoubleUnaryOperatorbindDouble(DoubleBinaryOperator f, double a)static LongUnaryOperatorbindLong(LongBinaryOperator f, long a)static <A, B, R> Predicate<B>bindToBool(Functions.ToBooleanBiFunction<A,B> f, A a)static <T> voidcall(T arg, Consumer<T> consumer)static <T, U> voidcall(T t, U u, BiConsumer<T,U> consumer)static <A, B, C> Function<A,C>compose(Function<B,C> f, Function<A,B> g)static <A, B> Function<A,Function<B,A>>constant()static <A, B> Function<B,A>constant(A a)Returns a function that ignores it's arguments and always returns the given value.static <A> ToDoubleFunction<A>constantDouble(double a)static <A> ToIntFunction<A>constantInt(int a)static <A> ToLongFunction<A>constantLong(long a)static <A, B, C> Function<A,Function<B,C>>curry(BiFunction<A,B,C> f)static <A, B, C> Function<A,Function<B,C>>curry(Function<Pair<A,B>,C> f)static <A, B, C> Function<Pair<A,B>,C>curryPair(BiFunction<A,B,C> f)static <A> DoubleFunction<A>doubleConstant(A a)static <A, R> Function1<A,R>f1(Function<A,R> f)static <A, B, R> Function2<A,B,R>f2(BiFunction<A,B,R> f)static <A, B, R> Function2<B,A,R>flip(BiFunction<A,B,R> f)static <A> UnaryOperator<A>id()Returns the identity function.static <A> IntFunction<A>intConstant(A a)static <A> LongFunction<A>longConstant(A a)static <T> Predicate<T>not(Predicate<T> predicate)static <T> Predicate<T>or(Predicate<? extends T>... ps)Combines many predicates into a predicate that accepts its input it if it passes one of these.static <T> Predicate<T>predicate(Function<T,Boolean> predicate)Turns a function that results in a boxed Boolean into a Predicate.static <A, B, C> BiFunction<A,B,C>uncurry(Function<A,Function<B,C>> f)static <A, B, C> Function<Pair<A,B>,C>uncurryPair(Function<A,Function<B,C>> f)
-
Constructor Details
-
Functions
public Functions()
-
-
Method Details
-
id
Returns the identity function. Identical toFunction.identity().- Type Parameters:
A- The type of the argument and return value.- Returns:
- A function that always returns what is passed into it.
-
constant
Returns a function that ignores it's arguments and always returns the given value.- Type Parameters:
A- The type of the argument which is returned by the returned function.B- The type of the returned functions parameter.- Parameters:
a- The given value.- Returns:
- The constant function.
-
constantInt
-
constantLong
-
constantDouble
-
intConstant
-
longConstant
-
doubleConstant
-
constant
-
compose
-
curry
@Nonnull public static <A, B, C> Function<A,Function<B,C>> curry(@Nonnull BiFunction<A,B,C> f) -
curryPair
@Nonnull public static <A, B, C> Function<Pair<A,B>,C> curryPair(@Nonnull BiFunction<A,B,C> f) -
curry
-
uncurry
@Nonnull public static <A, B, C> BiFunction<A,B,C> uncurry(@Nonnull Function<A,Function<B,C>> f) -
uncurryPair
-
not
-
and
Combines many predicates into a predicate that accepts its input only if it passes all predicates.- Type Parameters:
T- The type of the value to be tested by the predicates.- Parameters:
ps- The predicates - if no predicates are given the predicate will return true always.- Returns:
-
or
Combines many predicates into a predicate that accepts its input it if it passes one of these.- Type Parameters:
T- The type of the value to be tested by the predicates.- Parameters:
ps- The predicates - if no predicates are given the predicate will return false always.- Returns:
-
predicate
Turns a function that results in a boxed Boolean into a Predicate.- Type Parameters:
T- The type of the argument of the function.- Parameters:
predicate- The function.- Returns:
- The same function as a Predicate.
-
bind
-
bindToBool
@Nonnull public static <A, B, R> Predicate<B> bindToBool(@Nonnull Functions.ToBooleanBiFunction<A,B> f, A a) -
bindLong
-
bindDouble
-
flip
-
f1
-
f2
-
call
-
call
-
apply
-
apply
-