Skip to content

Commit

Permalink
[REFACTOR]: Unimportant change
Browse files Browse the repository at this point in the history
  • Loading branch information
csgn committed Aug 5, 2024
1 parent c871125 commit 052f876
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/scala/kuram/monoid/laws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ package monoid

package object laws {
trait MonoidLaws[T] {
implicit def M: Monoid[T]
implicit def F: Monoid[T]

/** must obey: `id + x == x + id` */
def identityLaw(x: T): Boolean =
(M.combine(M.empty, x) == x) == (M.combine(x, M.empty) == x)
def identity(x: T): Boolean =
(F.combine(F.empty, x) == x) == (F.combine(x, F.empty) == x)

/** must obey: `a + (b + c) = (a + b) + c` */
def associativity(a: T, b: T, c: T): Boolean =
M.combine(a, M.combine(b, c)) == M.combine(M.combine(a, b), c)
F.combine(a, F.combine(b, c)) == F.combine(F.combine(a, b), c)

/** must obey: `f(a) + f(b) == f(a + b)` */
def homomorphism[U](a: T, b: T)(f: T => U)(using U: Monoid[U]): Boolean =
U.combine(f(a), f(b)) == f(M.combine(a, b))
U.combine(f(a), f(b)) == f(F.combine(a, b))
}

object MonoidLaws {
def apply[T](using monoid: Monoid[T]): MonoidLaws[T] = new {
implicit def M: Monoid[T] = monoid
implicit def F: Monoid[T] = monoid
}
}
}

0 comments on commit 052f876

Please sign in to comment.