Package org.apache.groovy.util
Class Closures
java.lang.Object
org.apache.groovy.util.Closures
Helpers that return hybrid one-argument functions which are both
Closure and the appropriate java.util.function SAM
(Predicate, Function or Consumer).
For variants whose results are only the SAM type, see Lambdas.
- Since:
- 6.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic class -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,P> Closures.ConsumerClosure<T> curryWith(BiConsumer<? super T, ? super P> bc, P p) static <T,P, R> Closures.FunctionClosure<T, R> curryWith(BiFunction<? super T, ? super P, ? extends R> bf, P p) static <T,P> Closures.PredicateClosure<T> curryWith(BiPredicate<? super T, ? super P> bp, P p) Right-partials aBiPredicateand lifts the result into a hybrid usable as bothClosureandPredicate.static <T> Closures.ConsumerClosure<T>static <T,R> Closures.FunctionClosure<T, R> static <T> Closures.PredicateClosure<T>
-
Method Details
-
from
Lifts aPredicateinto a hybrid that is also aClosure. Ifpis already aClosures.PredicateClosureit is returned unchanged.Predicate<Integer> isEven = n -> n % 2 == 0 assert [1, 2, 3, 4].findAll(Closures.from(isEven)) == [2, 4]
- Since:
- 6.0.0
-
from
Lifts aFunctioninto a hybrid that is also aClosure. Iffis already aClosures.FunctionClosureit is returned unchanged.- Since:
- 6.0.0
-
from
Lifts aConsumerinto a hybrid that is also aClosure. Ifcis already aClosures.ConsumerClosureit is returned unchanged.- Since:
- 6.0.0
-
curryWith
public static <T,P> Closures.PredicateClosure<T> curryWith(BiPredicate<? super T, ? super P> bp, P p) Right-partials aBiPredicateand lifts the result into a hybrid usable as bothClosureandPredicate. Equivalent tofrom(Lambdas.curryWith(bp, p)).BiPredicate<Integer,Integer> divisibleBy = (n, d) -> n % d == 0 assert [1, 2, 3, 4, 5].findAll(curryWith(divisibleBy, 2)) == [2, 4]
- Since:
- 6.0.0
-
curryWith
public static <T,P, Closures.FunctionClosure<T,R> R> curryWith(BiFunction<? super T, ? super P, ? extends R> bf, P p) Right-partials aBiFunctionand lifts the result into a hybrid usable as bothClosureandFunction. Equivalent tofrom(Lambdas.curryWith(bf, p)).- Since:
- 6.0.0
-
curryWith
Right-partials aBiConsumerand lifts the result into a hybrid usable as bothClosureandConsumer. Equivalent tofrom(Lambdas.curryWith(bc, p)).- Since:
- 6.0.0
-