- A SemiGroup is a type class with a single operation append.
- If we throw away the right side of the SemiGroup, we get a first SemiGroup and if we through away the left side we get a second SemiGroup
- Don’t think of SemiGroup as a summation/addition (regardless of append)
- A good example ofa SemiGroup is a string, int, option…
- Law: Must be associative (but not necessarily commutative, string is not commutative, yet it is associative)
1
2
3
trait SemiGroup[A] {
def append(l: => A, r: => A): A // Note: lazy parameters
}
Comments powered by Disqus.