Class Monoids


  • public class Monoids
    extends Object
    Class with fields and methods providing monoid objects.
    Author:
    Herbert Praehofer
    • Field Detail

      • doublePlusMonoid

        public static Monoid<Double> doublePlusMonoid
        The monoid for double values, the plus operator and 0.0 as identity value.
      • doubleMultMonoid

        public static Monoid<Double> doubleMultMonoid
        The monoid for double values, the times operator and 1.0 as identity value.
      • intPlusMonoid

        public static Monoid<Integer> intPlusMonoid
        The monoid for integer values, the plus operator and 0 as identity value.
      • intTimesMonoid

        public static Monoid<Integer> intTimesMonoid
        The monoid for integer values, the times operator and 1 as identity value.
      • stringMonoid

        public static Monoid<String> stringMonoid
        The monoid for string values, the concatenation operator and "" as identity value.
      • booleanAndMonoid

        public static Monoid<Boolean> booleanAndMonoid
        The monoid for Boolean values, the and operator and true as identity value.
      • booleanOrMonoid

        public static Monoid<Boolean> booleanOrMonoid
        The monoid for Boolean values, the or operator and false as identity value.
    • Constructor Detail

      • Monoids

        public Monoids()
    • Method Detail

      • setMonoid

        public static <A> Monoid<Set<A>> setMonoid()
        Creates a monoid object for power sets for a generic value set A, the union operator and the empty set as identity value.
        Type Parameters:
        A - the type of values for the sets
        Returns:
        the monoid object
      • listMonoid

        public static <A> Monoid<List<A>> listMonoid()
        Creates a monoid object for list for a generic value set A, the list concatenation operator and the empty list as identity value.
        Type Parameters:
        A - the type of values for the list elements
        Returns:
        the monoid object
      • optionalMonoid

        public static <E> Monoid<Optional<E>> optionalMonoid​(Monoid<E> eMonoid)
        Creates a monoid for optional values where two values of non-empty optionals are combined by the given monoid.
        Type Parameters:
        E - the values contained in the optional
        Parameters:
        eMonoid - the monoid for the contained values
        Returns:
        the monoid for the optional values
      • mapMonoid

        public static <K,​V> Monoid<Map<K,​V>> mapMonoid​(Monoid<V> vMonoid)
        Creates a monoid for maps from a key to value where values are combined by the given monoid. The monoid for the values is used to combine values when in both maps entries for the same key exist.
        Type Parameters:
        K - the type of the keys in the map
        V - the type of the values in the map
        Parameters:
        vMonoid - the monoid for combining values
        Returns:
        the monoid for combining maps
      • implicitMonoid

        public static <M> Monoid<M> implicitMonoid​(M m)
        Returns a default monoid based on the type of a value.
        Type Parameters:
        M - the type of values
        Parameters:
        m - a single value
        Returns:
        a monoid for the value