-
-
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.
- Loading branch information
Showing
114 changed files
with
395 additions
and
344 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cats | ||
package free | ||
|
||
import cats.arrow.NaturalTransformation | ||
import cats.tests.CatsSuite | ||
import cats.laws.discipline.{ArbitraryK, FunctorTests, SerializableTests} | ||
|
||
import org.scalacheck.{Arbitrary, Gen} | ||
import org.scalacheck.Arbitrary.arbitrary | ||
import org.scalacheck.Prop.forAll | ||
|
||
class CoyonedaTests extends CatsSuite { | ||
implicit def coyonedaArbitraryK[F[_] : Functor](implicit F: ArbitraryK[F]): ArbitraryK[Coyoneda[F, ?]] = | ||
new ArbitraryK[Coyoneda[F, ?]]{ | ||
def synthesize[A: Arbitrary]: Arbitrary[Coyoneda[F, A]] = coyonedaArbitrary[F, A] | ||
} | ||
|
||
implicit def coyonedaArbitrary[F[_] : Functor, A : Arbitrary](implicit F: ArbitraryK[F]): Arbitrary[Coyoneda[F, A]] = | ||
Arbitrary(F.synthesize[A].arbitrary.map(Coyoneda.lift)) | ||
|
||
implicit def coyonedaEq[F[_]: Functor, A](implicit FA: Eq[F[A]]): Eq[Coyoneda[F, A]] = | ||
new Eq[Coyoneda[F, A]] { | ||
def eqv(a: Coyoneda[F, A], b: Coyoneda[F, A]): Boolean = FA.eqv(a.run, b.run) | ||
} | ||
|
||
checkAll("Coyoneda[Option, ?]", FunctorTests[Coyoneda[Option, ?]].functor[Int, Int, Int]) | ||
checkAll("Functor[Coyoneda[Option, ?]]", SerializableTests.serializable(Functor[Coyoneda[Option, ?]])) | ||
|
||
test("toYoneda and then toCoyoneda is identity")(check { | ||
// Issues inferring syntax for Eq, using instance explicitly | ||
forAll((y: Coyoneda[Option, Int]) => coyonedaEq[Option, Int].eqv(y.toYoneda.toCoyoneda, y)) | ||
}) | ||
|
||
test("transform and run is same as applying natural trans") { | ||
val nt = | ||
new NaturalTransformation[Option, List] { | ||
def apply[A](fa: Option[A]): List[A] = fa.toList | ||
} | ||
val o = Option("hello") | ||
val c = Coyoneda.lift(o) | ||
c.transform(nt).run should === (nt(o)) | ||
} | ||
} |
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,30 @@ | ||
package cats | ||
package free | ||
|
||
import cats.tests.CatsSuite | ||
import cats.laws.discipline.{ArbitraryK, FunctorTests, SerializableTests} | ||
|
||
import org.scalacheck.Arbitrary | ||
import org.scalacheck.Prop.forAll | ||
|
||
class YonedaTests extends CatsSuite { | ||
implicit def yonedaArbitraryK[F[_] : Functor](implicit F: ArbitraryK[F]): ArbitraryK[Yoneda[F, ?]] = | ||
new ArbitraryK[Yoneda[F, ?]]{ | ||
def synthesize[A: Arbitrary]: Arbitrary[Yoneda[F, A]] = | ||
Arbitrary(F.synthesize[A].arbitrary.map(Yoneda(_))) | ||
} | ||
|
||
implicit def yonedaArbitrary[F[_] : Functor : ArbitraryK, A : Arbitrary]: Arbitrary[Yoneda[F, A]] = yonedaArbitraryK[F].synthesize[A] | ||
|
||
implicit def yonedaEq[F[_]: Functor, A](implicit FA: Eq[F[A]]): Eq[Yoneda[F, A]] = | ||
new Eq[Yoneda[F, A]] { | ||
def eqv(a: Yoneda[F, A], b: Yoneda[F, A]): Boolean = FA.eqv(a.run, b.run) | ||
} | ||
|
||
checkAll("Yoneda[Option, ?]", FunctorTests[Yoneda[Option, ?]].functor[Int, Int, Int]) | ||
checkAll("Functor[Yoneda[Option, ?]]", SerializableTests.serializable(Functor[Yoneda[Option, ?]])) | ||
|
||
test("toCoyoneda and then toYoneda is identity")(check { | ||
forAll((y: Yoneda[Option, Int]) => y.toCoyoneda.toYoneda === y) | ||
}) | ||
} |
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,43 @@ | ||
package cats | ||
package jvm | ||
package std | ||
|
||
import scala.concurrent.{Await, Future} | ||
import scala.concurrent.{ExecutionContext => E} | ||
import scala.concurrent.duration.FiniteDuration | ||
|
||
import cats.std.FutureCoflatMap | ||
import cats.syntax.all._ | ||
|
||
object future extends FutureInstances0 | ||
|
||
trait FutureInstances0 extends FutureInstances1 { | ||
def futureComonad(atMost: FiniteDuration)(implicit ec: E): Comonad[Future] = | ||
new FutureCoflatMap with Comonad[Future] { | ||
def extract[A](x: Future[A]): A = | ||
Await.result(x, atMost) | ||
} | ||
|
||
def futureOrder[A: Order](atMost: FiniteDuration)(implicit ec: E): Eq[Future[A]] = | ||
new Order[Future[A]] { | ||
def compare(x: Future[A], y: Future[A]): Int = | ||
Await.result((x zip y).map { case (x, y) => x compare y }, atMost) | ||
} | ||
} | ||
|
||
trait FutureInstances1 extends FutureInstances2 { | ||
def futurePartialOrder[A: PartialOrder](atMost: FiniteDuration)(implicit ec: E): PartialOrder[Future[A]] = | ||
new PartialOrder[Future[A]] { | ||
def partialCompare(x: Future[A], y: Future[A]): Double = | ||
Await.result((x zip y).map { case (x, y) => x partialCompare y }, atMost) | ||
} | ||
|
||
} | ||
|
||
trait FutureInstances2 { | ||
def futureEq[A: Eq](atMost: FiniteDuration)(implicit ec: E): Eq[Future[A]] = | ||
new Eq[Future[A]] { | ||
def eqv(x: Future[A], y: Future[A]): Boolean = | ||
Await.result((x zip y).map { case (x, y) => x === y }, atMost) | ||
} | ||
} |
Oops, something went wrong.