Semigroup

public protocol Semigroup

Protocol for a semigroup, any algebraic structure that allows two of its elements to be combined into one, (A, A) -> A, for any of its elements and keeping associativity property for all the cases, for example: (a1 <> a2) <> a3 = a1 <> (a2 <> a3) for any as in A.

Axioms:

  • Totality
  • Associativity

For example, having a f(x) -> x and a g(x) -> x, one would be able to compose h = f <> g in a way that the new function h(x) will be similar to g(f(x))

  • Semigroup combine operation

    Declaration

    Swift

    static func <> (lhs: Self, rhs: Self) -> Self

    Parameters

    lhs

    First semigroup (A) -> A, let’s call it f(x)

    rhs

    Second semigroup (A) -> A, let’s call it g(x)

    Return Value

    a composed semigroup (A) -> A equivalent to g(f(x))