-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from fthomas/topic/strong-laws
Add StrongLaws and StrongTests
- Loading branch information
Showing
7 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cats.laws | ||
|
||
import cats.functor.Strong | ||
import cats.syntax.profunctor._ | ||
import cats.syntax.strong._ | ||
import cats.std.function._ | ||
|
||
/** | ||
* Laws that must be obeyed by any [[cats.functor.Strong]]. | ||
*/ | ||
trait StrongLaws[F[_, _]] extends ProfunctorLaws[F] { | ||
implicit override def F: Strong[F] | ||
|
||
def strongFirstDistributivity[A0, A1, B1, B2, C](fab: F[A1, B1], f: A0 => A1, g: B1 => B2): IsEq[F[(A0, C), (B2, C)]] = | ||
fab.dimap(f)(g).first[C] <-> fab.first[C].dimap(f.first[C])(g.first[C]) | ||
|
||
def strongSecondDistributivity[A0, A1, B1, B2, C](fab: F[A1, B1], f: A0 => A1, g: B1 => B2): IsEq[F[(C, A0), (C, B2)]] = | ||
fab.dimap(f)(g).second[C] <-> fab.second[C].dimap(f.second[C])(g.second[C]) | ||
} | ||
|
||
object StrongLaws { | ||
def apply[F[_, _]](implicit ev: Strong[F]): StrongLaws[F] = | ||
new StrongLaws[F] { def F = ev } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
laws/src/main/scala/cats/laws/discipline/StrongTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cats.laws | ||
package discipline | ||
|
||
import cats.Eq | ||
import cats.functor.Strong | ||
import org.scalacheck.Arbitrary | ||
import org.scalacheck.Prop._ | ||
|
||
trait StrongTests[F[_, _]] extends ProfunctorTests[F] { | ||
def laws: StrongLaws[F] | ||
|
||
def strong[A: Arbitrary, B: Arbitrary, C: Arbitrary, D: Arbitrary, E: Arbitrary, G: Arbitrary](implicit | ||
ArbFAB: Arbitrary[F[A, B]], | ||
ArbFBC: Arbitrary[F[B, C]], | ||
ArbFCD: Arbitrary[F[C, D]], | ||
EqFAB: Eq[F[A, B]], | ||
EqFAG: Eq[F[A, G]], | ||
EqFAEDE: Eq[F[(A, E), (D, E)]], | ||
EqFEAED: Eq[F[(E, A), (E, D)]] | ||
): RuleSet = | ||
new RuleSet { | ||
def name = "strong" | ||
def bases = Nil | ||
def parents = Seq(profunctor[A, B, C, D, E, G]) | ||
def props = Seq( | ||
"strong first distributivity" -> forAll(laws.strongFirstDistributivity[A, B, C, D, E] _), | ||
"strong second distributivity" -> forAll(laws.strongSecondDistributivity[A, B, C, D, E] _) | ||
) | ||
} | ||
} | ||
|
||
object StrongTests { | ||
def apply[F[_, _]: Strong]: StrongTests[F] = | ||
new StrongTests[F] { def laws = StrongLaws[F] } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters