Laws

We can see why this empty function is called the identity element; if you combine any object with the identity element, it returns the same object, as follows:

(3 |+| Monoid[Int].empty) == 3
("Hello identity" |+| Monoid[String].empty) == "Hello identity"
(Option(3) |+| Monoid[Option[Int]].empty) == Option(3)

This property is formally defined by the identity laws, as follows:

  • Left identity: For all x of type A, Monoid[A].empty |+| x == x
  • Right identity: For all x of type A, x |+| Monoid[A].empty == x
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset