Package org.apache.groovy.util
Class Lambdas
java.lang.Object
org.apache.groovy.util.Lambdas
Helpers that return
java.util.function types.
For variants whose results are also Closure
instances, see Closures.
- Since:
- 6.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,P> Consumer<T> curryWith(BiConsumer<? super T, ? super P> bc, P p) Right-partials aBiConsumerwith the supplied parameter, returning aConsumerthat fixes the second argument.static <T,P, R> Function<T, R> curryWith(BiFunction<? super T, ? super P, ? extends R> bf, P p) Right-partials aBiFunctionwith the supplied parameter, returning aFunctionthat fixes the second argument.static <T,P> Predicate<T> curryWith(BiPredicate<? super T, ? super P> bp, P p) Right-partials aBiPredicatewith the supplied parameter, returning aPredicatethat fixes the second argument.
-
Method Details
-
curryWith
Right-partials aBiPredicatewith the supplied parameter, returning aPredicatethat fixes the second argument.BiPredicate<Integer,Integer> divisibleBy = (n, d) -> n % d == 0 assert [1, 2, 3, 4, 5].stream().filter(curryWith(divisibleBy, 2)).toList() == [2, 4]
- Since:
- 6.0.0
-
curryWith
public static <T,P, Function<T,R> R> curryWith(BiFunction<? super T, ? super P, ? extends R> bf, P p) Right-partials aBiFunctionwith the supplied parameter, returning aFunctionthat fixes the second argument.BiFunction<String,Integer,String> repeat = (s, n) -> s * n assert ['a', 'b', 'c'].stream().map(curryWith(repeat, 3)).toList() == ['aaa', 'bbb', 'ccc']
- Since:
- 6.0.0
-
curryWith
Right-partials aBiConsumerwith the supplied parameter, returning aConsumerthat fixes the second argument.def sink = [] BiConsumer<String,List> addTo = (s, list) -> list << s ['a', 'b', 'c'].stream().forEach(curryWith(addTo, sink)) assert sink == ['a', 'b', 'c']
- Since:
- 6.0.0
-