forked from typelevel/cats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The law requires that extract(pure(a)) = a. This commit also updates the Monad* tests to use the new EqK typeclass, and also relocates some laws from ComonadLaws to CoflatMapLaws. There is a fair amount of plubming that had to change to get all of this working. A really important but thankless task will be to go through all of our tests and use EqK and ArbitraryK where possible to create a more consistent experience. This will only get harder once we have a new ScalaCheck release and we have to worry about Cogen as well.
- Loading branch information
Showing
17 changed files
with
195 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cats | ||
package laws | ||
|
||
/** | ||
* Laws that must be obeyed by any [[Bimonad]]. | ||
*/ | ||
trait BimonadLaws[F[_]] extends MonadLaws[F] with ComonadLaws[F] { | ||
implicit override def F: Bimonad[F] | ||
|
||
def pureExtractComposition[A](a: A): IsEq[A] = | ||
F.extract(F.pure(a)) <-> a | ||
} | ||
|
||
object BimonadLaws { | ||
def apply[F[_]](implicit ev: Bimonad[F]): BimonadLaws[F] = | ||
new BimonadLaws[F] { def F: Bimonad[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
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
30 changes: 30 additions & 0 deletions
30
laws/shared/src/main/scala/cats/laws/discipline/BimonadTests.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,30 @@ | ||
package cats | ||
package laws | ||
package discipline | ||
|
||
import org.scalacheck.Arbitrary | ||
import org.scalacheck.Prop | ||
import Prop._ | ||
|
||
trait BimonadTests[F[_]] extends MonadTests[F] with ComonadTests[F] { | ||
def laws: BimonadLaws[F] | ||
|
||
def bimonad[A: Arbitrary: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq]: RuleSet = | ||
new RuleSet { | ||
def name: String = "bimonad" | ||
def bases: Seq[(String, RuleSet)] = Nil | ||
def parents: Seq[RuleSet] = Seq(monad[A, B, C], comonad[A, B, C]) | ||
def props: Seq[(String, Prop)] = Seq( | ||
"pure and extract compose" -> forAll(laws.pureExtractComposition[A] _) | ||
) | ||
} | ||
} | ||
|
||
object BimonadTests { | ||
def apply[F[_]: Bimonad: ArbitraryK: EqK]: BimonadTests[F] = | ||
new BimonadTests[F] { | ||
def arbitraryK: ArbitraryK[F] = implicitly | ||
def eqK: EqK[F] = implicitly | ||
def laws: BimonadLaws[F] = BimonadLaws[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
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
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
Oops, something went wrong.