An identity element is a value that leaves another value unchanged when combined with it. For an operation combine, an identity empty satisfies combine(x, empty) == x and combine(empty, x) == x. The operation therefore has a neutral value on both sides. section 10.1
Common operations use different identity elements:
- String concatenation uses the empty string: s + "" and "" + s both produce s. section 10.1
- Integer addition uses 0, while integer multiplication uses 1. section 10.1
- Boolean conjunction uses true, Boolean disjunction uses false, and list concatenation uses Nil. section 10.1 section 10.9
trait Monoid[A]: def combine(a1: A, a2: A): A #1 def empty: A #2
A monoid records an associative combine operation together with its identity value, named empty. This interface separates the algebraic structure from any particular data type. section 10.1 section 10.9
Identity is one of the two monoid laws; the other is associativity. Together they make generic combination possible, including folding a list into one value with combineAll or mapping and combining with foldMap. The same pattern appears in monads, where unit acts as the identity for composition: composing with unit leaves a computation unchanged. section 10.9 section 11.4.3




