Class FunctionExtensions


  • @GwtCompatible
    public class FunctionExtensions
    extends java.lang.Object
    This is an extension library for functions, e.g. closures.
    See Also:
    Functions
    • Constructor Detail

      • FunctionExtensions

        public FunctionExtensions()
    • Method Detail

      • curry

        @Pure
        public static <P1,​RESULT> Functions.Function0<RESULT> curry​(Functions.Function1<? super P1,​? extends RESULT> function,
                                                                          P1 argument)
        Curries a function that takes one argument.
        Parameters:
        function - the original function. May not be null.
        argument - the fixed argument.
        Returns:
        a function that takes no arguments. Never null.
      • curry

        @Pure
        public static <P1,​P2,​RESULT> Functions.Function1<P2,​RESULT> curry​(Functions.Function2<? super P1,​? super P2,​? extends RESULT> function,
                                                                                            P1 argument)
        Curries a function that takes two arguments.
        Parameters:
        function - the original function. May not be null.
        argument - the fixed first argument of function.
        Returns:
        a function that takes one argument. Never null.
      • curry

        @Pure
        public static <P1,​P2,​P3,​RESULT> Functions.Function2<P2,​P3,​RESULT> curry​(Functions.Function3<? super P1,​? super P2,​? super P3,​? extends RESULT> function,
                                                                                                              P1 argument)
        Curries a function that takes three arguments.
        Parameters:
        function - the original function. May not be null.
        argument - the fixed first argument of function.
        Returns:
        a function that takes two arguments. Never null.
      • curry

        @Pure
        public static <P1,​P2,​P3,​P4,​RESULT> Functions.Function3<P2,​P3,​P4,​RESULT> curry​(Functions.Function4<? super P1,​? super P2,​? super P3,​? super P4,​? extends RESULT> function,
                                                                                                                                P1 argument)
        Curries a function that takes four arguments.
        Parameters:
        function - the original function. May not be null.
        argument - the fixed first argument of function.
        Returns:
        a function that takes three arguments. Never null.
      • curry

        @Pure
        public static <P1,​P2,​P3,​P4,​P5,​RESULT> Functions.Function4<P2,​P3,​P4,​P5,​RESULT> curry​(Functions.Function5<? super P1,​? super P2,​? super P3,​? super P4,​? super P5,​? extends RESULT> function,
                                                                                                                                                  P1 argument)
        Curries a function that takes five arguments.
        Parameters:
        function - the original function. May not be null.
        argument - the fixed first argument of function.
        Returns:
        a function that takes four arguments. Never null.
      • curry

        @Pure
        public static <P1,​P2,​P3,​P4,​P5,​P6,​RESULT> Functions.Function5<P2,​P3,​P4,​P5,​P6,​RESULT> curry​(Functions.Function6<? super P1,​? super P2,​? super P3,​? super P4,​? super P5,​? super P6,​? extends RESULT> function,
                                                                                                                                                                    P1 argument)
        Curries a function that takes six arguments.
        Parameters:
        function - the original function. May not be null.
        argument - the fixed first argument of function.
        Returns:
        a function that takes five arguments. Never null.
      • compose

        public static <V,​T,​R> Functions.Function1<V,​R> compose​(Functions.Function1<? super T,​? extends R> after,
                                                                                 Functions.Function1<? super V,​? extends T> before)
        Returns a composed function that first applies the before function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
        Type Parameters:
        V - the type of input to the before function, and to the composed function
        T - the type of output of the before function, and input to the after function
        R - the type of output to the after function, and to the composed function
        Parameters:
        after - the function to apply after the before function is applied
        before - the function to apply before the after function is applied
        Returns:
        a composed function that first applies the before function and then applies the after function
        Throws:
        java.lang.NullPointerException - if before or after is null
        Since:
        2.9
        See Also:
        andThen(Functions.Function1, Functions.Function1)
      • andThen

        public static <V,​T,​R> Functions.Function1<V,​R> andThen​(Functions.Function1<? super V,​? extends T> before,
                                                                                 Functions.Function1<? super T,​? extends R> after)
        Returns a composed function that first applies the before function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
        Type Parameters:
        V - the type of input to the before function, and to the composed function
        T - the type of output of the before function, and input to the after function
        R - the type of output to the after function, and to the composed function
        Parameters:
        before - the function to apply before the after function is applied
        after - the function to apply after the before function is applied
        Returns:
        a composed function that first applies the before function and then applies the after function
        Throws:
        java.lang.NullPointerException - if before or after is null
        Since:
        2.9
        See Also:
        compose(Functions.Function1, Functions.Function1)
      • andThen

        public static <V1,​V2,​T,​R> Functions.Function2<V1,​V2,​R> andThen​(Functions.Function2<? super V1,​? super V2,​? extends T> before,
                                                                                                     Functions.Function1<? super T,​? extends R> after)
        Returns a composed function that first applies the before function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
        Type Parameters:
        V1 - the type of the first parameter to the before function, and to the composed function
        V2 - the type of the second parameter to the before function, and to the composed function
        T - the type of output of the before function, and input to the after function
        R - the type of output to the after function, and to the composed function
        Parameters:
        before - the function to apply before the after function is applied
        after - the function to apply after the before function is applied
        Returns:
        a composed function that first applies the before function and then applies the after function
        Throws:
        java.lang.NullPointerException - if before or after is null
        Since:
        2.9
        See Also:
        compose(Functions.Function1, Functions.Function1)
      • andThen

        public static <T> Procedures.Procedure1<T> andThen​(Procedures.Procedure1<? super T> before,
                                                           Procedures.Procedure1<? super T> after)
        Returns a composed Procedure1 that performs, in sequence, the before operation followed by the after operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing the before operation throws an exception, the after operation will not be performed.
        Type Parameters:
        T - the type of input for the before operation
        Parameters:
        before - the operation to perform first
        after - the operation to perform afterwards
        Returns:
        a composed Procedure1 that performs in sequence the before operation followed by the after operation
        Throws:
        java.lang.NullPointerException - if before or after is null
        Since:
        2.9
      • andThen

        public static Procedures.Procedure0 andThen​(Procedures.Procedure0 before,
                                                    Procedures.Procedure0 after)
        Returns a composed Procedure1 that performs, in sequence, the before operation followed by the after operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing the before operation throws an exception, the after operation will not be performed.
        Parameters:
        before - the operation to perform first
        after - the operation to perform afterwards
        Returns:
        a composed Procedure1 that performs in sequence the before operation followed by the after operation
        Throws:
        java.lang.NullPointerException - if before or after is null
        Since:
        2.9