Interface Monoid<A>

    • Method Detail

      • identity

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

        default A reduceLeft​(java.lang.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:
        ReduceLeft
      • reduceRight

        default A reduceRight​(java.lang.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:
        ReduceRight
      • foldMap

        default <B> A foldMap​(Fn1<? super B,​? extends A> fn,
                              java.lang.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:
        Map, reduceLeft(Iterable)
      • foldLeft

        default A foldLeft​(A a,
                           java.lang.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:
        FoldLeft
      • foldRight

        default Lazy<A> foldRight​(A a,
                                  java.lang.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:
        FoldRight
      • 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