Skip to content

Commit

Permalink
Add id
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Sep 27, 2017
1 parent 53343b3 commit 9026c96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion kernel-laws/src/main/scala/cats/kernel/laws/MonoidLaws.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cats.kernel.laws

import cats.kernel.Monoid
import cats.kernel.{Eq, Monoid}

trait MonoidLaws[A] extends SemigroupLaws[A] {
override implicit def S: Monoid[A]
Expand All @@ -20,6 +20,10 @@ trait MonoidLaws[A] extends SemigroupLaws[A] {
def combineAll(xs: Vector[A]): IsEq[A] =
S.combineAll(xs) <-> (S.empty +: xs).reduce(S.combine)

def isId(x: A, eqv: Eq[A]): IsEq[Boolean] = {
eqv.eqv(x, S.empty) <-> S.isEmpty(x)(eqv)
}

}

object MonoidLaws {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cats.kernel.laws.discipline
package cats
package kernel
package laws
package discipline

import cats.kernel.{Monoid, Eq}
import cats.kernel.laws.MonoidLaws
import cats.kernel.instances.boolean._
import org.scalacheck.Arbitrary
import org.scalacheck.Prop.forAll

Expand All @@ -17,6 +19,7 @@ trait MonoidLawTests[A] extends SemigroupLawTests[A] {
"right identity" -> forAll(laws.rightIdentity _),
"combine all" -> forAll(laws.combineAll _),
"collect0" -> forAll(laws.collect0 _),
"is id" -> forAll((a: A) => laws.isId(a, eqA)),
"repeat0" -> forAll(laws.repeat0 _))

}
Expand Down

0 comments on commit 9026c96

Please sign in to comment.