org.qi4j.functional

## Class Functions

- java.lang.Object
- - org.qi4j.functional.Functions

-     public final class Functions
      extends Object

  Utility functions. Combine these with methods in Iterables, for example. See FunctionsTest for usages.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <T> Comparator<T>` | `comparator(Function<T,Comparable> comparableFunction)` Creates a comparator that takes a function as input.
    `static <A,B,C> Function2<Function<? super B,C>,Function<A,B>,Function<A,C>>` | `compose()`
    `static <FROM,MIDDLE,TO> Function<FROM,TO>` | `compose(Function<? super MIDDLE,TO> outer, Function<FROM,MIDDLE> inner)` compose(F1(M,T),F2(F,M)) = F1(F2(F)) -> T
    `static <T> Function<T,Integer>` | `count(Specification<T> specification)` Count the number of items in an iterable that matches a given specification.
    `static <T> Function<T,T>` | `filteredMap(Specification<T> specification, Function<T,T> function)` Only apply given function on objects that satisfies the given specification.
    `static <FROM,TO> Function<FROM,TO>` | `fromMap(Map<FROM,TO> map)`
    `static <TO,FROM extends TO> Function<FROM,TO>` | `identity()`
    `static <T> Function<T,Integer>` | `indexOf(Specification<T> specification)` Find out the index of an item matching a given specification in an iterable.
    `static <T> int` | `indexOf(T item, Iterable<T> iterable)` Find out the index of an item in an iterable.
    `static Function<Number,Integer>` | `intSum()`
    `static Function<Number,Long>` | `longSum()`
    `static <T> Function<T,T>` | `withDefault(T defaultValue)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### compose

          public static <A,B,C> Function2<Function<? super B,C>,Function<A,B>,Function<A,C>> compose()

    - #### compose

          public static <FROM,MIDDLE,TO> Function<FROM,TO> compose(Function<? super MIDDLE,TO> outer,
                                                   Function<FROM,MIDDLE> inner)

      compose(F1(M,T),F2(F,M)) = F1(F2(F)) -> T
      Parameters:
        `outer` - The outer/encapsulating function
        `inner` - The inner/encapsulated function
      Returns:
        A function that is a composition of an outer and inner function.

    - #### identity

          public static <TO,FROM extends TO> Function<FROM,TO> identity()

    - #### fromMap

          public static <FROM,TO> Function<FROM,TO> fromMap(Map<FROM,TO> map)

    - #### withDefault

          public static <T> Function<T,T> withDefault(T defaultValue)

    - #### longSum

          public static Function<Number,Long> longSum()

    - #### intSum

          public static Function<Number,Integer> intSum()

    - #### count

          public static <T> Function<T,Integer> count(Specification<T> specification)

      Count the number of items in an iterable that matches a given specification. Sample usage: last( map( count( in( "X" ) ), iterable( "X","Y","X","X","Y" ) ) ) Returns: 3
      Type Parameters:
        `T` - The type of the items.
      Parameters:
        `specification` - The items that adhere to the Specification is counted.
      Returns:
        A Function that can count items adhering to a Specification.

    - #### indexOf

          public static <T> Function<T,Integer> indexOf(Specification<T> specification)

      Find out the index of an item matching a given specification in an iterable. Returns -1 if it is not found.
      Type Parameters:
        `T` - The type of the items.
      Parameters:
        `specification` - The Specification that specifies what to look for.
      Returns:
        A Function that will provide the 'index' where the Specifcation is fulfilled. The Function will return -1 if the current item doesn't fulfill the Specification.

    - #### indexOf

          public static <T> int indexOf(T item,
                        Iterable<T> iterable)

      Find out the index of an item in an iterable.
      Type Parameters:
        `T` - The type of the items.
      Parameters:
        `item` - The item to look for.
        `iterable` - The Iterable to search.
      Returns:
        The index in the Iterable where the item is located.

    - #### filteredMap

          public static <T> Function<T,T> filteredMap(Specification<T> specification,
                                      Function<T,T> function)

      Only apply given function on objects that satisfies the given specification.
      Type Parameters:
        `T` - The type of the items.
      Parameters:
        `specification` - A Specification that specifies what should be included in the filtered result.
        `function` - The function to be applied to items that fulfills the Specification
      Returns:
        A Function that performs the filter operation when applied to Iterables.

    - #### comparator

          public static <T> Comparator<T> comparator(Function<T,Comparable> comparableFunction)

      Creates a comparator that takes a function as input. The returned comparator will use the function once for each item in the list to be sorted by Collections.sort. This should be used if the function to generate the sort key from an object is expensive, so that it is not done many times for each item in a list.
      Type Parameters:
        `T` - The generic type to be used.
      Parameters:
        `comparableFunction` - The Function that the Comparator will delegate to.
      Returns:
        A comparator that uses a Function for the compare operation.