Class Lambdas

java.lang.Object
org.apache.groovy.util.Lambdas

public class Lambdas extends Object
Helpers that return java.util.function types.

For variants whose results are also Closure instances, see Closures.

Since:
6.0.0
  • Method Details

    • curryWith

      public static <T, P> Predicate<T> curryWith(BiPredicate<? super T,? super P> bp, P p)
      Right-partials a BiPredicate with the supplied parameter, returning a Predicate that 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, R> Function<T,R> curryWith(BiFunction<? super T,? super P,? extends R> bf, P p)
      Right-partials a BiFunction with the supplied parameter, returning a Function that 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

      public static <T, P> Consumer<T> curryWith(BiConsumer<? super T,? super P> bc, P p)
      Right-partials a BiConsumer with the supplied parameter, returning a Consumer that 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