Class Semigroups


  • public final class Semigroups
    extends java.lang.Object
    Semigroup instances.
    Since:
    3.1
    See Also:
    Monoids
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Semigroups()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <L,​R>
      Semigroup<Either<L,​R>>
      either​(Semigroup<L> lS, Semigroup<R> rS)
      Sums up values inside either, if both are left or right.
      static <A> Semigroup<A> first()
      Return the first value, ignore the second
      static <A,​B>
      Semigroup<java.util.function.Function<A,​B>>
      function​(Semigroup<B> sb)
      A semigroup for functions.
      static <A> Semigroup<A> last()
      Return the last value, ignore the first
      static <A extends java.lang.Comparable<A>>
      Semigroup<A>
      max()
      A semigroup that yields the maximum of comparable values.
      static <A> Semigroup<A> max​(java.util.Comparator<A> comparator)
      A semigroup that yields the maximum of by a comparator.
      static <A extends java.lang.Comparable<A>>
      Semigroup<A>
      min()
      A semigroup that yields the minimum of comparable values.
      static <A> Semigroup<A> min​(java.util.Comparator<A> comparator)
      A semigroup that yields the minimum of by a comparator.
      • Methods inherited from class java.lang.Object

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

      • intMaximum

        public static final Semigroup<java.lang.Integer> intMaximum
        A semigroup that yields the maximum of integers.
      • intMinimum

        public static final Semigroup<java.lang.Integer> intMinimum
        A semigroup that yields the minimum of integers.
      • bigintMaximum

        public static final Semigroup<java.math.BigInteger> bigintMaximum
        A semigroup that yields the maximum of big integers.
      • bigintMinimum

        public static final Semigroup<java.math.BigInteger> bigintMinimum
        A semigroup that yields the minimum of big integers.
      • bigDecimalMaximum

        public static final Semigroup<java.math.BigDecimal> bigDecimalMaximum
        A semigroup that yields the maximum of big decimals.
      • bigDecimalMinimum

        public static final Semigroup<java.math.BigDecimal> bigDecimalMinimum
        A semigroup that yields the minimum of big decimals.
      • longMaximum

        public static final Semigroup<java.lang.Long> longMaximum
        A semigroup that yields the maximum of longs.
      • longMinimum

        public static final Semigroup<java.lang.Long> longMinimum
        A semigroup that yields the minimum of longs.
    • Constructor Detail

      • Semigroups

        private Semigroups()
    • Method Detail

      • first

        public static <A> Semigroup<A> first()
        Return the first value, ignore the second
        Type Parameters:
        A - result type
        Returns:
        a Semigroup that ignores the second input
      • last

        public static <A> Semigroup<A> last()
        Return the last value, ignore the first
        Type Parameters:
        A - result type
        Returns:
        a Semigroup that ignores the first input
      • function

        public static <A,​B> Semigroup<java.util.function.Function<A,​B>> function​(Semigroup<B> sb)
        A semigroup for functions.
        Type Parameters:
        A - input type
        B - composable output type
        Parameters:
        sb - The semigroup for the codomain.
        Returns:
        A semigroup for functions.
      • max

        public static <A> Semigroup<A> max​(java.util.Comparator<A> comparator)
        A semigroup that yields the maximum of by a comparator.
        Type Parameters:
        A - result type
        Parameters:
        comparator - the comparator used to define the max of two value.
        Returns:
        A max semigroup.
      • min

        public static <A> Semigroup<A> min​(java.util.Comparator<A> comparator)
        A semigroup that yields the minimum of by a comparator.
        Type Parameters:
        A - result type
        Parameters:
        comparator - the comparator used to define the min of two value.
        Returns:
        A min semigroup.
      • max

        public static <A extends java.lang.Comparable<A>> Semigroup<A> max()
        A semigroup that yields the maximum of comparable values.
        Type Parameters:
        A - result type
        Returns:
        A max semigroup.
      • min

        public static <A extends java.lang.Comparable<A>> Semigroup<A> min()
        A semigroup that yields the minimum of comparable values.
        Type Parameters:
        A - result type
        Returns:
        A min semigroup.
      • either

        public static <L,​R> Semigroup<Either<L,​R>> either​(Semigroup<L> lS,
                                                                      Semigroup<R> rS)
        Sums up values inside either, if both are left or right. Returns first left otherwise.
        • right(v1) + right(v2) → right(v1 + v2)
        • right(v1) + -left(v2) → left(v2)
        • left(v1) + right(v2) → left(v1)
        • left(v1) + left(v2) → left(v1 + v2)
        Type Parameters:
        L - left type
        R - right type
        Parameters:
        lS - Semigroup for left values
        rS - Semigroup for right values
        Returns:
        A semigroup that Sums up values inside either.