Class Functions


  • public final class Functions
    extends Object
    • Method Detail

      • throwing

        public static <T,​V> Function<T,​V> throwing​(ThrowingFunction<T,​V> throwingFunction)
        Allows a lambda or anonymous inner class that needs to throw a checked exception to be safely wrapped as a Function that will throw a RuntimeException, wrapping the checked exception that is the cause.
      • throwing

        public static <T,​V> Function<T,​V> throwing​(ThrowingFunction<T,​V> throwingFunction,
                                                               Function2<T,​? super Throwable,​? extends RuntimeException> rethrow)
        Allows a lambda or anonymous inner class that needs to throw a checked exception to be safely wrapped as a Function that will throw a user specified RuntimeException based on the provided function. The function is passed the current element and the checked exception that was thrown as context arguments.
      • cast

        public static <T,​V> Function<T,​V> cast​(Function<T,​V> function)
        Allows a Java 8 lambda and method reference to be used in a method taking a Function as a parameter without any ambiguity.
      • getPassThru

        public static <T> Function<T,​T> getPassThru()
        Alias for identity(). Inlineable.
        See Also:
        identity()
      • identity

        public static <T> Function<T,​T> identity()
        Since:
        6.0
      • getFixedValue

        public static <T,​V> Function<T,​V> getFixedValue​(V value)
      • withDefault

        public static <T,​V> Function<T,​V> withDefault​(Function<? super T,​? extends V> function,
                                                                  V defaultValue)
      • nullSafe

        public static <T,​V> Function<T,​V> nullSafe​(Function<? super T,​? extends V> function)
      • nullSafe

        public static <T,​V> Function<T,​V> nullSafe​(Function<? super T,​? extends V> function,
                                                               V nullValue)
      • firstOfPair

        public static <V1> Function<Pair<V1,​?>,​V1> firstOfPair()
      • secondOfPair

        public static <V2> Function<Pair<?,​V2>,​V2> secondOfPair()
      • swappedPair

        public static <S,​T> Function<Pair<S,​T>,​Pair<T,​S>> swappedPair()
        Swap the input pair and return the swapped pair.
        Returns:
        A function that gets the swapped pair Iterable
      • bind

        public static <T,​P,​R> Function<T,​R> bind​(Function2<? super T,​? super P,​? extends R> function,
                                                                   P parameter)
        Bind the parameter passed to a Function2 into a new Function.
        Parameters:
        function - The Function2 to delegate the invocation to.
        parameter - The parameter the use in the invocation of the delegate function.
        Returns:
        A new Function
      • bind

        public static <T1,​T2> Procedure<T1> bind​(Procedure<? super T2> delegate,
                                                       Function<? super T1,​T2> function)
        Bind the input of a Procedure to the result of a function, returning a new Procedure.
        Parameters:
        delegate - The Procedure to delegate the invocation to.
        function - The Function that will create the input for the delegate
        Returns:
        A new Procedure
      • bind

        public static <T1,​T2> ObjectIntProcedure<T1> bind​(ObjectIntProcedure<? super T2> delegate,
                                                                Function<? super T1,​T2> function)
        Bind the input of a ObjectIntProcedure to the result of a function, returning a new ObjectIntProcedure.
        Parameters:
        delegate - The ObjectIntProcedure to delegate the invocation to.
        function - The Function that will create the input for the delegate
        Returns:
        A new ObjectIntProcedure
      • bind

        public static <T1,​T2,​T3> Procedure2<T1,​T3> bind​(Procedure2<? super T2,​T3> delegate,
                                                                          Function<? super T1,​T2> function)
        Bind the input of the first argument of a Procedure2 to the result of a function, returning a new Procedure2.
        Parameters:
        delegate - The Procedure2 to delegate the invocation to.
        function - The Function that will create the input for the delegate
        Returns:
        A new Procedure2
      • firstNotNullValue

        public static <T,​V> Function<T,​V> firstNotNullValue​(Function<T,​V>... functions)
      • firstNotEmptyCollectionValue

        public static <T1,​T2,​I extends Iterable<T2>> Function<T1,​I> firstNotEmptyCollectionValue​(Function<T1,​I>... functions)
      • ifTrue

        public static <T,​V> Function<T,​V> ifTrue​(Predicate<? super T> predicate,
                                                             Function<? super T,​? extends V> function)
      • ifElse

        public static <T,​V> Function<T,​V> ifElse​(Predicate<? super T> predicate,
                                                             Function<? super T,​? extends V> trueFunction,
                                                             Function<? super T,​? extends V> falseFunction)
      • caseDefault

        public static <T extends Comparable<? super T>,​V> CaseFunction<T,​V> caseDefault​(Function<? super T,​? extends V> defaultFunction)
      • caseDefault

        public static <T extends Comparable<? super T>,​V> CaseFunction<T,​V> caseDefault​(Function<? super T,​? extends V> defaultFunction,
                                                                                                    Predicate<? super T> predicate,
                                                                                                    Function<? super T,​? extends V> function)
      • synchronizedEach

        public static <T,​V> Function<T,​V> synchronizedEach​(Function<T,​V> function)
      • pair

        public static <T,​V1,​V2> Function<T,​Pair<V1,​V2>> pair​(Function<? super T,​V1> function1,
                                                                                     Function<? super T,​V2> function2)
      • getKeyFunction

        public static <K> Function<Map.Entry<K,​?>,​K> getKeyFunction()
        Returns:
        A function that gets the key out of a Map.Entry
      • getValueFunction

        public static <V> Function<Map.Entry<?,​V>,​V> getValueFunction()
        Returns:
        A function that gets the value out of a Map.Entry
      • getSizeOf

        public static Function<Iterable<?>,​Integer> getSizeOf()
        Returns:
        A function that gets the size of an Iterable