Package: org.apache.groovy.util

## [Java] Class Closures

- org.apache.groovy.util.Closures

-     public class Closures
      extends Object

  Helpers that return hybrid one-argument functions which are both Closure and the appropriate 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 classes
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `Closures.ConsumerClosure` | Hybrid one-argument function that is both a Closure and a Consumer.
    `static class` | `Closures.FunctionClosure` | Hybrid one-argument function that is both a Closure and a Function.
    `static class` | `Closures.PredicateClosure` | Hybrid one-argument function that is both a Closure and a Predicate.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `<T, P>` | `public static PredicateClosure<T>` | `curryWith(BiPredicate<? super T, ? super P> bp, P p)` Right-partials a BiPredicate and lifts the result into a hybrid usable as both Closure and Predicate.
    `<T, P, R>` | `public static FunctionClosure<T, R>` | `curryWith(BiFunction<? super T, ? super P, ? extends R> bf, P p)` Right-partials a BiFunction and lifts the result into a hybrid usable as both Closure and Function.
    `<T, P>` | `public static ConsumerClosure<T>` | `curryWith(BiConsumer<? super T, ? super P> bc, P p)` Right-partials a BiConsumer and lifts the result into a hybrid usable as both Closure and Consumer.
    `<T>` | `public static PredicateClosure<T>` | `from(Predicate<T> p)` Lifts a Predicate into a hybrid that is also a Closure.
    `<T, R>` | `public static FunctionClosure<T, R>` | `from(Function<T, R> f)` Lifts a Function into a hybrid that is also a Closure.
    `<T>` | `public static ConsumerClosure<T>` | `from(Consumer<T> c)` Lifts a Consumer into a hybrid that is also a Closure.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### <T, P> public static PredicateClosure<T> curryWith(BiPredicate<? super T, ? super P> bp, P p)

      Right-partials a BiPredicate and lifts the result into a hybrid usable as both Closure and Predicate. Equivalent to `from(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

    - #### <T, P, R> public static FunctionClosure<T, R> curryWith(BiFunction<? super T, ? super P, ? extends R> bf, P p)

      Right-partials a BiFunction and lifts the result into a hybrid usable as both Closure and Function. Equivalent to `from(Lambdas.curryWith(bf, p))`.

      Since:
        6.0.0

    - #### <T, P> public static ConsumerClosure<T> curryWith(BiConsumer<? super T, ? super P> bc, P p)

      Right-partials a BiConsumer and lifts the result into a hybrid usable as both Closure and Consumer. Equivalent to `from(Lambdas.curryWith(bc, p))`.

      Since:
        6.0.0

    - #### <T> public static PredicateClosure<T> from(Predicate<T> p)

      Lifts a Predicate into a hybrid that is also a Closure. If `p` is already a PredicateClosure it 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

    - #### <T, R> public static FunctionClosure<T, R> from(Function<T, R> f)

      Lifts a Function into a hybrid that is also a Closure. If `f` is already a FunctionClosure it is returned unchanged.

      Since:
        6.0.0

    - #### <T> public static ConsumerClosure<T> from(Consumer<T> c)

      Lifts a Consumer into a hybrid that is also a Closure. If `c` is already a ConsumerClosure it is returned unchanged.

      Since:
        6.0.0