Interface Monoid<A>

Type Parameters:
A - the element type this Monoid is formed over
All Superinterfaces:
Applicative<Fn1<A,A>,Fn1<A,?>>, Cartesian<A,Fn1<A,A>,Fn1<?,?>>, Cocartesian<A,Fn1<A,A>,Fn1<?,?>>, Contravariant<A,Profunctor<?,Fn1<A,A>,Fn1<?,?>>>, Fn1<A,Fn1<A,A>>, Fn2<A,A,A>, Functor<Fn1<A,A>,Fn1<A,?>>, Monad<Fn1<A,A>,Fn1<A,?>>, MonadReader<A,Fn1<A,A>,Fn1<A,?>>, MonadRec<Fn1<A,A>,Fn1<A,?>>, MonadWriter<A,Fn1<A,A>,Fn1<A,?>>, Profunctor<A,Fn1<A,A>,Fn1<?,?>>, Semigroup<A>
All Known Implementing Classes:
And, Concat, Endo, First, Join, Last, MergeHMaps, Or, PutAll, Trivial, Union, Xor

public interface Monoid<A> extends Semigroup<A>
A Monoid is the pairing of a Semigroup with an identity element.
  • Method Details

    • identity

      A identity()
      The identity element of this monoid.
      Returns:
      the identity
    • reduceLeft

      default A reduceLeft(Iterable<A> as)
      Catamorphism under this monoid using ReduceLeft, where the result is the reduction, or, if empty, the identity of this monoid.
      Parameters:
      as - the elements to reduce
      Returns:
      the reduction, or identity() if empty
      See Also:
    • reduceRight

      default A reduceRight(Iterable<A> as)
      Catamorphism under this monoid using ReduceRight, where the result is the reduction, or, if empty, the identity of this monoid.
      Parameters:
      as - an Iterable of elements in this monoid
      Returns:
      the reduction, or identity() if empty
      See Also:
    • foldMap

      default <B> A foldMap(Fn1<? super B,? extends A> fn, Iterable<B> bs)
      Homomorphism combined with catamorphism. Convert an Iterable<B> to an Iterable<A> (that is, an Iterable of elements this monoid is formed over), then reduce the result from left to right. Under algebraic data types, this is isomorphic to a flatMap.
      Type Parameters:
      B - the input Iterable element type
      Parameters:
      fn - the mapping function from A to B
      bs - the Iterable of Bs
      Returns:
      the folded result under this Monoid
      See Also:
    • foldLeft

      default A foldLeft(A a, Iterable<A> as)
      Catamorphism under this semigroup using FoldLeft, where the binary operator is this semigroup, and the starting accumulator is provided.
      Specified by:
      foldLeft in interface Semigroup<A>
      Parameters:
      a - the starting accumulator
      as - the elements to fold over
      Returns:
      the folded result
      See Also:
    • foldRight

      default Lazy<A> foldRight(A a, Iterable<A> as)
      Catamorphism under this semigroup using FoldRight, where the binary operator is this semigroup, and the starting accumulator is provided.
      Specified by:
      foldRight in interface Semigroup<A>
      Parameters:
      a - the starting accumulator
      as - the elements to fold over
      Returns:
      the folded result
      See Also:
    • flip

      default Monoid<A> flip()
      Flip the order of the arguments.
      Specified by:
      flip in interface Fn2<A,A,A>
      Specified by:
      flip in interface Semigroup<A>
      Returns:
      an Fn2<B, A, C>
    • monoid

      static <A> Monoid<A> monoid(Semigroup<A> semigroup, A identity)
      Promote a Semigroup to a Monoid by supplying an identity element.
      Type Parameters:
      A - the element type of this monoid
      Parameters:
      semigroup - the semigroup
      identity - the identity element
      Returns:
      the monoid
    • monoid

      static <A> Monoid<A> monoid(Semigroup<A> semigroup, Fn0<A> identityFn0)