Class Functional


  • public final class Functional
    extends java.lang.Object
    Provides set of generally useful higher-order functions.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <F,​T>
      com.google.common.base.Function<F,​T>
      constant​(T value)
      Creates a constant function that returns value for any input.
      static <VAL,​ACCU>
      ACCU
      foldl​(CombiningFunction<VAL,​ACCU> f, ACCU z, java.lang.Iterable<? extends VAL> xs)
      Version of foldl as it is known in functional programming word.
      static <VAL,​ACCU>
      ACCU
      foldlNull​(CombiningFunction<VAL,​ACCU> f, ACCU z, java.lang.Iterable<VAL> xs)
      Version of foldl as it is known in functional programming word handling the null values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • foldlNull

        public static <VAL,​ACCU> ACCU foldlNull​(CombiningFunction<VAL,​ACCU> f,
                                                      ACCU z,
                                                      java.lang.Iterable<VAL> xs)
        Version of foldl as it is known in functional programming word handling the null values.

        Applied to a binary operator, a starting value (typically the left-identity of the operator), and a list, reduces the list using the binary operator, from left to right:

        Type Parameters:
        VAL - type of values to be folded
        ACCU - resulting value
        Parameters:
        f - reducing operator
        z - starting value
        xs - the list to be reduced
        Returns:
        reduced result
        See Also:
        foldl(com.im.commons.CombiningFunction<VAL, ACCU>, ACCU, java.lang.Iterable<? extends VAL>)
      • foldl

        public static <VAL,​ACCU> ACCU foldl​(CombiningFunction<VAL,​ACCU> f,
                                                  ACCU z,
                                                  java.lang.Iterable<? extends VAL> xs)
        Version of foldl as it is known in functional programming word.

        Applied to a binary operator, a starting value (typically the left-identity of the operator), and a list, reduces the list using the binary operator, from left to right:

        Type Parameters:
        VAL - type of values to be folded
        ACCU - resulting value
        Parameters:
        f - reducing operator
        z - starting value
        xs - the list to be reduced
        Returns:
        reduced result
        See Also:
        foldlNull(com.im.commons.CombiningFunction<VAL, ACCU>, ACCU, java.lang.Iterable<VAL>)
      • constant

        public static <F,​T> com.google.common.base.Function<F,​T> constant​(T value)
        Creates a constant function that returns value for any input. I.e. it ignore its input parameter.

        This function is similar to the Functions.constant(E) from Guava library but is generic in its input parameter which fits better in some scenarios.

        Type Parameters:
        F - type of input parameter (mapping from)
        T - type of output parameter (mapping to)
        Parameters:
        value - the constant value for the function to return
        Returns:
        a constant function that always returns value