Interface Reducible<E>

  • Type Parameters:
    E - the type of values to reduce

    public interface Reducible<E>
    Interface for reducible structures.
    Author:
    Herbert Praehofer
    • Method Detail

      • from

        static <E> Reducible<E> from​(Iterable<E> iterable)
        Creates a reducible object for an iterable object.
        Type Parameters:
        E - the type of values
        Parameters:
        iterable - the iterable object
        Returns:
        the reducible object
      • from

        static <E> Reducible<E> from​(Tree<E> tree)
        Creates a reducible object for an tree object.
        Type Parameters:
        E - the type of values
        Parameters:
        tree - the tree object
        Returns:
        the reducible object
      • reduceMap

        <R> R reduceMap​(Function<? super E,​? extends R> mapper,
                        Monoid<R> monoid)
        First maps the elements and then reduces the mapped elements based on the given monoid.
        Type Parameters:
        R - the type of the mapped values
        Parameters:
        mapper - the mapping function
        monoid - the monoid for reduction
        Returns:
        the reduced value
      • reduce

        default E reduce​(Monoid<E> monoid)
        Reduces the values based on the given monoid. Uses reduceMap with an identity mapping.
        Parameters:
        monoid - the monoid for reduction
        Returns:
        the reduced value
      • toSet

        default Set<E> toSet()
        Creates a set of the elements. The set is created by a reduction using the set monoid.
        Returns:
        the set of elements
      • toList

        default List<E> toList()
        Creates a list of the elements. The list is created by a reduction using the list monoid.
        Returns:
        the list of elements
      • count

        default int count()
        Counts the elements. Maps each element to value 1 and does a reduction using the monoid for integer values with the plus operator.
        Returns:
        the number of elements
      • sum

        default int sum​(ToIntFunction<? super E> toIntFn)
        Builds the sum of the mapped integer values. First maps the elements to an integer value using the given mapping function and then reduces the integer values using the monoid for integer values with the plus operator.
        Parameters:
        toIntFn - the mapping function
        Returns:
        the sum of mapped values
      • minimum

        default <C extends Comparable<C>> C minimum​(C max,
                                                    Function<? super E,​? extends C> toComparableFn)
        Computes the minimum of mapped values. First maps the elements to a comparable element and then does a reduction using a monoid for the minimum value.
        Type Parameters:
        C - the type of mapped values
        Parameters:
        max - the identity value for the monoid
        toComparableFn - the mapping function for mapping the elements to a comparable element
        Returns:
        the minimum value
      • maximum

        default <C extends Comparable<C>> C maximum​(C min,
                                                    Function<? super E,​? extends C> toComparableFn)
        Computes the maximum of mapped values. First maps the elements to a comparable element and then does a reduction using a monoid for the maximum value.
        Type Parameters:
        C - the type of mapped values
        Parameters:
        min - the identity value for the monoid
        toComparableFn - the mapping function for mapping the elements to a comparable element
        Returns:
        the maximum value