What are monoids?

After the preceding brief introduction to monoids, let's get straight to business and look at a formal definition of a monoid:

A monoid is a purely algebraic structure, which means that it is defined only by its algebra. All monoids must conform to the so-called monoid laws.

The preceding definition is definitely not enough to have a good understanding of monoids, so let's break it into pieces in this section and try to come up with a better one.

First, let's clarify the term algebraic structure:

Algebraic: It is defined only by its algebra, for example, the operations it supports and the laws it conforms to.

Now that we know that monoids are defined only by the operations they support, let's have a look at the monoid laws: ...

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.