Home SemiGroup
Post
Cancel

SemiGroup

  • 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
}

Resources

  1. Functional Scala by John A. De Goes (Toronto Edition)
  2. Scalaz SemiGroup
This post is licensed under CC BY 4.0 by the author.
Contents

Monoid

Type Classes

Comments powered by Disqus.