Skip to content

Commit

Permalink
added distributeIdentityLaw
Browse files Browse the repository at this point in the history
  • Loading branch information
kailuowang committed Dec 12, 2017
1 parent b91e9bb commit e14f8d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions laws/src/main/scala/cats/laws/DistributiveLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import cats.syntax.distributive._
trait DistributiveLaws[F[_]] extends FunctorLaws[F] {
implicit override def F: Distributive[F]

def distributeIdentity[A, B](fa: F[A], f: A => B): IsEq[F[B]] = {
fa.distribute[Id, B](f) <-> F.map(fa)(f)
}

def cosequenceIdentity[A](fa: F[A]): IsEq[F[A]] = {
F.cosequence[Id, A](fa) <-> fa
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ trait DistributiveTests[F[_]] extends FunctorTests[F] {
CogenB: Cogen[B],
CogenC: Cogen[C],
EqFA: Eq[F[A]],
EqFB: Eq[F[B]],
EqFC: Eq[F[C]],
EqA: Eq[A],
EqFYXC: Eq[F[Y[X[C]]]],
Expand All @@ -29,6 +30,7 @@ trait DistributiveTests[F[_]] extends FunctorTests[F] {
def bases: Seq[(String, RuleSet)] = Nil
def parents: Seq[RuleSet] = Seq(functor[A, B, C])
def props: Seq[(String, Prop)] = Seq(
"distributive distribute identity" -> forAll(laws.distributeIdentity[A, B] _),
"distributive identity" -> forAll(laws.cosequenceIdentity[A] _),
"distributive composition" -> forAll(laws.composition[A, B, C, X, Y] _),
"distributive double cosequence identity" -> forAll(laws.cosequenceTwiceIsId[A, Y] _)
Expand Down

0 comments on commit e14f8d8

Please sign in to comment.