Monoid

public protocol Monoid : Semigroup

A monoid is an algebraic structure that has the same properties as a semigroup, with an empty element.

  • Empty element.

    The empty element must obey the monoid laws:

    a.combine(empty()) == empty().combine(a) == a
    

    That is, combining any element with empty must return the original element.

    Declaration

    Swift

    static func empty() -> Self

    Return Value

    A value of the implementing type satisfying the monoid laws.

  • combineAll(_:) Extension method

    Combines a variable number of values of the implementing type, in the order provided in the call.

    Declaration

    Swift

    static func combineAll(_ elems: Self...) -> Self

    Parameters

    elems

    Values of the implementing type.

    Return Value

    A single value of the implementing type representing the combination of all the parameter values.

  • combineAll(_:) Extension method

    Combines an array of values of the implementing type, in the order provided in the call.

    Declaration

    Swift

    static func combineAll(_ elems: [Self]) -> Self

    Parameters

    elems

    Values of the implementing type.

    Return Value

    A single value of the implementing type representing the combination of all the parameter values.