diff --git a/build.sbt b/build.sbt index ea0efd22..b8a2cae9 100644 --- a/build.sbt +++ b/build.sbt @@ -194,8 +194,8 @@ lazy val props = final val Scala3Versions = List("3.0.0") final val Scala3Version = Scala3Versions.head -// final val ProjectScalaVersion = Scala2Version - final val ProjectScalaVersion = Scala3Version + final val ProjectScalaVersion = Scala2Version +// final val ProjectScalaVersion = Scala3Version lazy val licenses = List("MIT" -> url("http://opensource.org/licenses/MIT")) diff --git a/cats-effect/src/main/scala-2/effectie/cats/Fx.scala b/cats-effect/src/main/scala-2/effectie/cats/Fx.scala index 3e12dd3e..1a79a9f9 100644 --- a/cats-effect/src/main/scala-2/effectie/cats/Fx.scala +++ b/cats-effect/src/main/scala-2/effectie/cats/Fx.scala @@ -1,28 +1,18 @@ package effectie.cats import cats.effect.IO -import cats.{Id, Monad} +import cats.Id import effectie.{CommonFx, OldEffectConstructor} import scala.concurrent.{ExecutionContext, Future} -trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with CommonFx[F] with OldEffectConstructor[F] with Monad[F] +trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with CommonFx[F] with OldEffectConstructor[F] object Fx { def apply[F[_]: Fx]: Fx[F] = implicitly[Fx[F]] implicit object IoFx extends Fx[IO] { - @inline private val syncIo: Monad[IO] = cats.effect.Sync[IO] - - @inline override def pure[A](x: A): IO[A] = pureOf(x) - - @inline override def flatMap[A, B](fa: IO[A])(f: A => IO[B]): IO[B] = - syncIo.flatMap(fa)(f) - - @inline override def tailRecM[A, B](a: A)(f: A => IO[Either[A, B]]): IO[B] = - syncIo.tailRecM(a)(f) - @inline override def effectOf[A](a: => A): IO[A] = IO(a) @inline override def pureOf[A](a: A): IO[A] = IO.pure(a) @@ -38,33 +28,10 @@ object Fx { with EffectConstructor[Future] with FxCtor[Future] with CommonFx.CommonFutureFx - with OldEffectConstructor.OldFutureEffectConstructor { - - @inline private val futureInstance: Monad[Future] = cats.instances.future.catsStdInstancesForFuture - - @inline override def pure[A](x: A): Future[A] = - pureOf(x) - - @inline override def flatMap[A, B](fa: Future[A])(f: A => Future[B]): Future[B] = - futureInstance.flatMap(fa)(f) - - @inline override def tailRecM[A, B](a: A)(f: A => Future[Either[A, B]]): Future[B] = - futureInstance.tailRecM(a)(f) - - } + with OldEffectConstructor.OldFutureEffectConstructor implicit object IdFx extends Fx[Id] { - @inline private val idInstance: Monad[Id] = cats.catsInstancesForId - - @inline override def pure[A](x: A): Id[A] = pureOf(x) - - @inline override def flatMap[A, B](fa: Id[A])(f: A => Id[B]): Id[B] = - idInstance.flatMap(fa)(f) - - @inline override def tailRecM[A, B](a: A)(f: A => Id[Either[A, B]]): Id[B] = - idInstance.tailRecM(a)(f) - @inline override def effectOf[A](a: => A): Id[A] = a @inline override def pureOf[A](a: A): Id[A] = a diff --git a/cats-effect/src/main/scala-3/effectie/cats/Fx.scala b/cats-effect/src/main/scala-3/effectie/cats/Fx.scala index 55045b8b..12206e49 100644 --- a/cats-effect/src/main/scala-3/effectie/cats/Fx.scala +++ b/cats-effect/src/main/scala-3/effectie/cats/Fx.scala @@ -6,23 +6,13 @@ import effectie.{CommonFx, OldEffectConstructor} import scala.concurrent.{ExecutionContext, Future} -trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with CommonFx[F] with OldEffectConstructor[F] with Monad[F] +trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with CommonFx[F] with OldEffectConstructor[F] object Fx { def apply[F[_]: Fx]: Fx[F] = summon[Fx[F]] given ioFx: Fx[IO] with { - private val syncIo: Monad[IO] = Sync[IO] - - inline override def pure[A](x: A): IO[A] = pureOf(x) - - inline override def flatMap[A, B](fa: IO[A])(f: A => IO[B]): IO[B] = - syncIo.flatMap(fa)(f) - - inline override def tailRecM[A, B](a: A)(f: A => IO[Either[A, B]]): IO[B] = - syncIo.tailRecM(a)(f) - inline override def effectOf[A](a: => A): IO[A] = IO(a) inline override def pureOf[A](a: A): IO[A] = IO.pure(a) @@ -38,32 +28,10 @@ object Fx { with EffectConstructor[Future] with FxCtor[Future] with CommonFx.CommonFutureFx - with OldEffectConstructor.OldFutureEffectConstructor { - - private val futureInstance: Monad[Future] = cats.instances.future.catsStdInstancesForFuture - - inline override def pure[A](x: A): Future[A] = - pureOf(x) - - inline override def flatMap[A, B](fa: Future[A])(f: A => Future[B]): Future[B] = - futureInstance.flatMap(fa)(f) - - inline override def tailRecM[A, B](a: A)(f: A => Future[Either[A, B]]): Future[B] = - futureInstance.tailRecM(a)(f) - } + with OldEffectConstructor.OldFutureEffectConstructor given idFx: Fx[Id] with { - private val idInstance: Monad[Id] = cats.catsInstancesForId - - inline override def pure[A](x: A): Id[A] = pureOf(x) - - inline override def flatMap[A, B](fa: Id[A])(f: A => Id[B]): Id[B] = - idInstance.flatMap(fa)(f) - - inline override def tailRecM[A, B](a: A)(f: A => Id[Either[A, B]]): Id[B] = - idInstance.tailRecM(a)(f) - inline override def effectOf[A](a: => A): Id[A] = a inline override def pureOf[A](a: A): Id[A] = a diff --git a/cats-effect/src/test/scala-2/effectie/cats/FxSpec.scala b/cats-effect/src/test/scala-2/effectie/cats/FxSpec.scala index 654b190a..0be5f20e 100644 --- a/cats-effect/src/test/scala-2/effectie/cats/FxSpec.scala +++ b/cats-effect/src/test/scala-2/effectie/cats/FxSpec.scala @@ -1,7 +1,7 @@ package effectie.cats import cats.effect._ -import cats.{Eq, Id} +import cats.{Eq, Id, Monad} import effectie.ConcurrentSupport import hedgehog._ import hedgehog.runner._ @@ -88,7 +88,7 @@ object FxSpec extends Properties { implicit val ioFx: Fx[IO] = Fx.IoFx - MonadSpec.testMonadLaws[IO] + MonadSpec.testMonadLaws[IO]("IO") } } @@ -165,7 +165,7 @@ object FxSpec extends Properties { Await.result(future, waitFor) } - MonadSpec.testMonadLaws[Future] + MonadSpec.testMonadLaws[Future]("Future") } } @@ -207,7 +207,10 @@ object FxSpec extends Properties { actual ==== expected } - def testMonadLaws: List[Test] = MonadSpec.testMonadLaws[Id] + def testMonadLaws: List[Test] = { + val idInstance: Monad[Id] = cats.catsInstancesForId + MonadSpec.testMonadLaws[Id]("Id") + } } diff --git a/cats-effect/src/test/scala-3/effectie/cats/FxSpec.scala b/cats-effect/src/test/scala-3/effectie/cats/FxSpec.scala index aaead90d..ecace959 100644 --- a/cats-effect/src/test/scala-3/effectie/cats/FxSpec.scala +++ b/cats-effect/src/test/scala-3/effectie/cats/FxSpec.scala @@ -1,7 +1,7 @@ package effectie.cats import cats.effect.* -import cats.{Eq, Id} +import cats.{Eq, Id, Monad} import effectie.ConcurrentSupport import hedgehog.* import hedgehog.runner.* @@ -86,7 +86,7 @@ object FxSpec extends Properties { implicit val ioFx: Fx[IO] = Fx.ioFx - MonadSpec.testMonadLaws[IO] + MonadSpec.testMonadLaws[IO]("IO") } } @@ -161,7 +161,7 @@ object FxSpec extends Properties { Await.result(future, waitFor) } - MonadSpec.testMonadLaws[Future] + MonadSpec.testMonadLaws[Future]("Future") } } @@ -201,7 +201,10 @@ object FxSpec extends Properties { actual ==== expected } - def testMonadLaws: List[Test] = MonadSpec.testMonadLaws[Id] + def testMonadLaws: List[Test] = { + given idMonad: Monad[Id] = cats.catsInstancesForId + MonadSpec.testMonadLaws[Id]("Id") + } } diff --git a/cats-effect/src/test/scala/effectie/cats/MonadSpec.scala b/cats-effect/src/test/scala/effectie/cats/MonadSpec.scala index a7429f0e..afd32d2e 100644 --- a/cats-effect/src/test/scala/effectie/cats/MonadSpec.scala +++ b/cats-effect/src/test/scala/effectie/cats/MonadSpec.scala @@ -1,9 +1,9 @@ package effectie.cats -import cats.Eq +import cats.{Eq, Monad} import hedgehog.runner.Test object MonadSpec { - def testMonadLaws[F[_]: Fx](implicit eqF: Eq[F[Int]]): List[Test] = - effectie.testing.cats.MonadSpec.testAllLaws[F] + def testMonadLaws[F[_]: Fx: Monad](name: String)(implicit eqF: Eq[F[Int]]): List[Test] = + effectie.testing.cats.MonadSpec.testAllLaws[F](s"Fx[$name]") } diff --git a/cats-effect3/src/main/scala-2/effectie/cats/Fx.scala b/cats-effect3/src/main/scala-2/effectie/cats/Fx.scala index 3e12dd3e..1a79a9f9 100644 --- a/cats-effect3/src/main/scala-2/effectie/cats/Fx.scala +++ b/cats-effect3/src/main/scala-2/effectie/cats/Fx.scala @@ -1,28 +1,18 @@ package effectie.cats import cats.effect.IO -import cats.{Id, Monad} +import cats.Id import effectie.{CommonFx, OldEffectConstructor} import scala.concurrent.{ExecutionContext, Future} -trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with CommonFx[F] with OldEffectConstructor[F] with Monad[F] +trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with CommonFx[F] with OldEffectConstructor[F] object Fx { def apply[F[_]: Fx]: Fx[F] = implicitly[Fx[F]] implicit object IoFx extends Fx[IO] { - @inline private val syncIo: Monad[IO] = cats.effect.Sync[IO] - - @inline override def pure[A](x: A): IO[A] = pureOf(x) - - @inline override def flatMap[A, B](fa: IO[A])(f: A => IO[B]): IO[B] = - syncIo.flatMap(fa)(f) - - @inline override def tailRecM[A, B](a: A)(f: A => IO[Either[A, B]]): IO[B] = - syncIo.tailRecM(a)(f) - @inline override def effectOf[A](a: => A): IO[A] = IO(a) @inline override def pureOf[A](a: A): IO[A] = IO.pure(a) @@ -38,33 +28,10 @@ object Fx { with EffectConstructor[Future] with FxCtor[Future] with CommonFx.CommonFutureFx - with OldEffectConstructor.OldFutureEffectConstructor { - - @inline private val futureInstance: Monad[Future] = cats.instances.future.catsStdInstancesForFuture - - @inline override def pure[A](x: A): Future[A] = - pureOf(x) - - @inline override def flatMap[A, B](fa: Future[A])(f: A => Future[B]): Future[B] = - futureInstance.flatMap(fa)(f) - - @inline override def tailRecM[A, B](a: A)(f: A => Future[Either[A, B]]): Future[B] = - futureInstance.tailRecM(a)(f) - - } + with OldEffectConstructor.OldFutureEffectConstructor implicit object IdFx extends Fx[Id] { - @inline private val idInstance: Monad[Id] = cats.catsInstancesForId - - @inline override def pure[A](x: A): Id[A] = pureOf(x) - - @inline override def flatMap[A, B](fa: Id[A])(f: A => Id[B]): Id[B] = - idInstance.flatMap(fa)(f) - - @inline override def tailRecM[A, B](a: A)(f: A => Id[Either[A, B]]): Id[B] = - idInstance.tailRecM(a)(f) - @inline override def effectOf[A](a: => A): Id[A] = a @inline override def pureOf[A](a: A): Id[A] = a diff --git a/cats-effect3/src/main/scala-3/effectie/cats/Fx.scala b/cats-effect3/src/main/scala-3/effectie/cats/Fx.scala index 55045b8b..12206e49 100644 --- a/cats-effect3/src/main/scala-3/effectie/cats/Fx.scala +++ b/cats-effect3/src/main/scala-3/effectie/cats/Fx.scala @@ -6,23 +6,13 @@ import effectie.{CommonFx, OldEffectConstructor} import scala.concurrent.{ExecutionContext, Future} -trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with CommonFx[F] with OldEffectConstructor[F] with Monad[F] +trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with CommonFx[F] with OldEffectConstructor[F] object Fx { def apply[F[_]: Fx]: Fx[F] = summon[Fx[F]] given ioFx: Fx[IO] with { - private val syncIo: Monad[IO] = Sync[IO] - - inline override def pure[A](x: A): IO[A] = pureOf(x) - - inline override def flatMap[A, B](fa: IO[A])(f: A => IO[B]): IO[B] = - syncIo.flatMap(fa)(f) - - inline override def tailRecM[A, B](a: A)(f: A => IO[Either[A, B]]): IO[B] = - syncIo.tailRecM(a)(f) - inline override def effectOf[A](a: => A): IO[A] = IO(a) inline override def pureOf[A](a: A): IO[A] = IO.pure(a) @@ -38,32 +28,10 @@ object Fx { with EffectConstructor[Future] with FxCtor[Future] with CommonFx.CommonFutureFx - with OldEffectConstructor.OldFutureEffectConstructor { - - private val futureInstance: Monad[Future] = cats.instances.future.catsStdInstancesForFuture - - inline override def pure[A](x: A): Future[A] = - pureOf(x) - - inline override def flatMap[A, B](fa: Future[A])(f: A => Future[B]): Future[B] = - futureInstance.flatMap(fa)(f) - - inline override def tailRecM[A, B](a: A)(f: A => Future[Either[A, B]]): Future[B] = - futureInstance.tailRecM(a)(f) - } + with OldEffectConstructor.OldFutureEffectConstructor given idFx: Fx[Id] with { - private val idInstance: Monad[Id] = cats.catsInstancesForId - - inline override def pure[A](x: A): Id[A] = pureOf(x) - - inline override def flatMap[A, B](fa: Id[A])(f: A => Id[B]): Id[B] = - idInstance.flatMap(fa)(f) - - inline override def tailRecM[A, B](a: A)(f: A => Id[Either[A, B]]): Id[B] = - idInstance.tailRecM(a)(f) - inline override def effectOf[A](a: => A): Id[A] = a inline override def pureOf[A](a: A): Id[A] = a diff --git a/cats-effect3/src/test/scala-2/effectie/cats/FxSpec.scala b/cats-effect3/src/test/scala-2/effectie/cats/FxSpec.scala index 9f3f6364..159c7c50 100644 --- a/cats-effect3/src/test/scala-2/effectie/cats/FxSpec.scala +++ b/cats-effect3/src/test/scala-2/effectie/cats/FxSpec.scala @@ -2,7 +2,7 @@ package effectie.cats import cats.effect._ import cats.effect.testkit.TestContext -import cats.{Eq, Id} +import cats.{Eq, Id, Monad} import effectie.ConcurrentSupport import hedgehog._ import hedgehog.runner._ @@ -388,6 +388,8 @@ object FxSpec extends Properties { actual ==== expected } + implicit val idInstance: Monad[Id] = cats.catsInstancesForId + def testMonadLaws1_Identity: Property = MonadSpec.test1_Identity[Id] diff --git a/cats-effect3/src/test/scala-3/effectie/cats/FxSpec.scala b/cats-effect3/src/test/scala-3/effectie/cats/FxSpec.scala index 9e6ebd83..baca42b5 100644 --- a/cats-effect3/src/test/scala-3/effectie/cats/FxSpec.scala +++ b/cats-effect3/src/test/scala-3/effectie/cats/FxSpec.scala @@ -3,7 +3,7 @@ package effectie.cats import cats.effect.* import cats.effect.testkit.TestContext import cats.effect.unsafe.IORuntime -import cats.{Eq, Id} +import cats.{Eq, Id, Monad} import effectie.ConcurrentSupport import hedgehog.* import hedgehog.runner.* @@ -384,6 +384,8 @@ object FxSpec extends Properties { actual ==== expected } + given idInstance: Monad[Id] = cats.catsInstancesForId + def testMonadLaws1_Identity: Property = MonadSpec.test1_Identity[Id] diff --git a/cats-effect3/src/test/scala/effectie/cats/MonadSpec.scala b/cats-effect3/src/test/scala/effectie/cats/MonadSpec.scala index 0aadff1a..a7fc66e2 100644 --- a/cats-effect3/src/test/scala/effectie/cats/MonadSpec.scala +++ b/cats-effect3/src/test/scala/effectie/cats/MonadSpec.scala @@ -1,18 +1,18 @@ package effectie.cats -import cats.Eq -import effectie.testing.cats.{Specs, Gens} +import cats.{Eq, Monad} +import effectie.testing.cats.{Gens, Specs} import hedgehog.Property object MonadSpec { - def test1_Identity[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property = + def test1_Identity[F[_]: Fx: Monad](implicit eqF: Eq[F[Int]]): Property = Specs .MonadLaws .identity[F]( Gens.genFA[F, Int](Gens.genInt(Int.MinValue, Int.MaxValue)), ) - def test2_Composition[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property = + def test2_Composition[F[_]: Fx: Monad](implicit eqF: Eq[F[Int]]): Property = Specs .MonadLaws .composition[F]( @@ -20,14 +20,14 @@ object MonadSpec { Gens.genIntToInt, ) - def test3_IdentityAp[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property = + def test3_IdentityAp[F[_]: Fx: Monad](implicit eqF: Eq[F[Int]]): Property = Specs .MonadLaws .identityAp[F]( Gens.genFA[F, Int](Gens.genInt(Int.MinValue, Int.MaxValue)), ) - def test4_Homomorphism[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property = + def test4_Homomorphism[F[_]: Fx: Monad](implicit eqF: Eq[F[Int]]): Property = Specs .MonadLaws .homomorphism[F]( @@ -35,7 +35,7 @@ object MonadSpec { Gens.genIntToInt, ) - def test5_Interchange[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property = + def test5_Interchange[F[_]: Fx: Monad](implicit eqF: Eq[F[Int]]): Property = Specs .MonadLaws .interchange[F]( @@ -43,7 +43,7 @@ object MonadSpec { Gens.genIntToInt, ) - def test6_CompositionAp[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property = + def test6_CompositionAp[F[_]: Fx: Monad](implicit eqF: Eq[F[Int]]): Property = Specs .MonadLaws .compositionAp[F]( @@ -51,7 +51,7 @@ object MonadSpec { Gens.genIntToInt, ) - def test7_LeftIdentity[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property = + def test7_LeftIdentity[F[_]: Fx: Monad](implicit eqF: Eq[F[Int]]): Property = Specs .MonadLaws .leftIdentity[F]( @@ -59,14 +59,14 @@ object MonadSpec { Gens.genAToMonadA(Gens.genIntToInt) ) - def test8_RightIdentity[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property = + def test8_RightIdentity[F[_]: Fx: Monad](implicit eqF: Eq[F[Int]]): Property = Specs .MonadLaws .rightIdentity[F]( Gens.genFA[F, Int](Gens.genInt(Int.MinValue, Int.MaxValue)), ) - def test9_Associativity[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property = + def test9_Associativity[F[_]: Fx: Monad](implicit eqF: Eq[F[Int]]): Property = Specs .MonadLaws .associativity[F]( diff --git a/effectie-monix/src/main/scala/effectie/monix/Fx.scala b/effectie-monix/src/main/scala/effectie/monix/Fx.scala index 1b8f241a..646e8d4b 100644 --- a/effectie-monix/src/main/scala/effectie/monix/Fx.scala +++ b/effectie-monix/src/main/scala/effectie/monix/Fx.scala @@ -1,7 +1,7 @@ package effectie.monix import cats.effect.IO -import cats.{Id, Monad} +import cats.Id import monix.eval.Task import scala.concurrent.{ExecutionContext, Future} @@ -9,23 +9,13 @@ import scala.concurrent.{ExecutionContext, Future} /** @author Kevin Lee * @since 2021-05-16 */ -trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with effectie.CommonFx[F] with Monad[F] +trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with effectie.CommonFx[F] object Fx { def apply[F[_]: Fx]: Fx[F] = implicitly[Fx[F]] implicit object TaskFx extends Fx[Task] { - @inline private val taskMonad: Monad[Task] = monix.eval.Task.catsAsync - - @inline override def pure[A](x: A): Task[A] = pureOf(x) - - @inline override def flatMap[A, B](fa: Task[A])(f: A => Task[B]): Task[B] = - taskMonad.flatMap(fa)(f) - - @inline override def tailRecM[A, B](a: A)(f: A => Task[Either[A, B]]): Task[B] = - taskMonad.tailRecM(a)(f) - @inline override def effectOf[A](a: => A): Task[A] = Task(a) @inline override def pureOf[A](a: A): Task[A] = Task.now(a) @@ -35,16 +25,6 @@ object Fx { implicit object IoFx extends Fx[IO] { - @inline private val syncIo: Monad[IO] = cats.effect.Sync[IO] - - @inline override def pure[A](x: A): IO[A] = pureOf(x) - - @inline override def flatMap[A, B](fa: IO[A])(f: A => IO[B]): IO[B] = - syncIo.flatMap(fa)(f) - - @inline override def tailRecM[A, B](a: A)(f: A => IO[Either[A, B]]): IO[B] = - syncIo.tailRecM(a)(f) - @inline override def effectOf[A](a: => A): IO[A] = IO(a) @inline override def pureOf[A](a: A): IO[A] = IO.pure(a) @@ -59,33 +39,10 @@ object Fx { extends Fx[Future] with EffectConstructor[Future] with FxCtor[Future] - with effectie.CommonFx.CommonFutureFx { - - @inline private val futureInstance: Monad[Future] = cats.instances.future.catsStdInstancesForFuture - - @inline override def pure[A](x: A): Future[A] = - pureOf(x) - - @inline override def flatMap[A, B](fa: Future[A])(f: A => Future[B]): Future[B] = - futureInstance.flatMap(fa)(f) - - @inline override def tailRecM[A, B](a: A)(f: A => Future[Either[A, B]]): Future[B] = - futureInstance.tailRecM(a)(f) - - } + with effectie.CommonFx.CommonFutureFx implicit object IdFx extends Fx[Id] { - @inline private val idInstance: Monad[Id] = cats.catsInstancesForId - - @inline override def pure[A](x: A): Id[A] = pureOf(x) - - @inline override def flatMap[A, B](fa: Id[A])(f: A => Id[B]): Id[B] = - idInstance.flatMap(fa)(f) - - @inline override def tailRecM[A, B](a: A)(f: A => Id[Either[A, B]]): Id[B] = - idInstance.tailRecM(a)(f) - @inline override def effectOf[A](a: => A): Id[A] = a @inline override def pureOf[A](a: A): Id[A] = a diff --git a/effectie-monix/src/test/scala/effectie/monix/FxSpec.scala b/effectie-monix/src/test/scala/effectie/monix/FxSpec.scala index 66b842fd..93242ffe 100644 --- a/effectie-monix/src/test/scala/effectie/monix/FxSpec.scala +++ b/effectie-monix/src/test/scala/effectie/monix/FxSpec.scala @@ -1,6 +1,6 @@ package effectie.monix -import cats.{Id, Eq} +import cats.{Eq, Id, Monad} import cats.effect.IO import effectie.ConcurrentSupport import hedgehog._ @@ -96,7 +96,7 @@ object FxSpec extends Properties { implicit val ioFx: Fx[Task] = Fx.TaskFx - MonadSpec.testMonadLaws[Task] + MonadSpec.testMonadLaws[Task]("Task") } } @@ -158,7 +158,7 @@ object FxSpec extends Properties { implicit val ioFx: Fx[IO] = Fx.IoFx - MonadSpec.testMonadLaws[IO] + MonadSpec.testMonadLaws[IO]("IO") } } @@ -235,7 +235,7 @@ object FxSpec extends Properties { Await.result(future, waitFor) } - MonadSpec.testMonadLaws[Future] + MonadSpec.testMonadLaws[Future]("Future") } } @@ -277,7 +277,10 @@ object FxSpec extends Properties { actual ==== expected } - def testMonadLaws: List[Test] = MonadSpec.testMonadLaws[Id] + def testMonadLaws: List[Test] = { + implicit val idInstance: Monad[Id] = cats.catsInstancesForId + MonadSpec.testMonadLaws[Id]("Id") + } } diff --git a/effectie-monix/src/test/scala/effectie/monix/MonadSpec.scala b/effectie-monix/src/test/scala/effectie/monix/MonadSpec.scala index 19ffbf6a..857f7766 100644 --- a/effectie-monix/src/test/scala/effectie/monix/MonadSpec.scala +++ b/effectie-monix/src/test/scala/effectie/monix/MonadSpec.scala @@ -1,9 +1,9 @@ package effectie.monix -import cats.Eq +import cats.{Eq, Monad} import hedgehog.runner.Test object MonadSpec { - def testMonadLaws[F[_]: Fx](implicit eqF: Eq[F[Int]]): List[Test] = - effectie.testing.cats.MonadSpec.testAllLaws[F] + def testMonadLaws[F[_]: Fx: Monad](name: String)(implicit eqF: Eq[F[Int]]): List[Test] = + effectie.testing.cats.MonadSpec.testAllLaws[F](s"Fx[$name]") } diff --git a/scalaz-effect/src/main/scala/effectie/scalaz/Fx.scala b/scalaz-effect/src/main/scala/effectie/scalaz/Fx.scala index 682d8a97..7974ca13 100644 --- a/scalaz-effect/src/main/scala/effectie/scalaz/Fx.scala +++ b/scalaz-effect/src/main/scala/effectie/scalaz/Fx.scala @@ -3,26 +3,19 @@ package effectie.scalaz import effectie.{CommonFx, OldEffectConstructor} import scalaz.Scalaz.Id import scalaz.effect.IO -import scalaz.{Monad, Scalaz} import scala.concurrent.{ExecutionContext, Future} -trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with CommonFx[F] with OldEffectConstructor[F] with Monad[F] +trait Fx[F[_]] extends EffectConstructor[F] with FxCtor[F] with CommonFx[F] with OldEffectConstructor[F] object Fx { def apply[F[_]: Fx]: Fx[F] = implicitly[Fx[F]] implicit object IoFx extends Fx[IO] { - @inline private val ioMonad: Monad[IO] = IO.ioMonad - - @inline override def point[A](a: => A): IO[A] = pureOf(a) - - @inline override def bind[A, B](fa: IO[A])(f: A => IO[B]): IO[B] = ioMonad.bind(fa)(f) - @inline override def effectOf[A](a: => A): IO[A] = IO(a) - @inline override def pureOf[A](a: A): IO[A] = ioMonad.pure(a) + @inline override def pureOf[A](a: A): IO[A] = effectOf(a) @inline override val unitOf: IO[Unit] = IO.ioUnit } @@ -36,26 +29,10 @@ object Fx { with EffectConstructor[Future] with FxCtor[Future] with CommonFx.CommonFutureFx - with OldEffectConstructor.OldFutureEffectConstructor { - - @inline private val futureInstance: Monad[Future] = scalaz.Scalaz.futureInstance - - @inline override def bind[A, B](fa: Future[A])(f: A => Future[B]): Future[B] = - futureInstance.bind(fa)(f) - - @inline override def point[A](a: => A): Future[A] = futureInstance.point(a) - - } + with OldEffectConstructor.OldFutureEffectConstructor implicit object IdFx extends Fx[Id] { - @inline private val idInstance: Monad[Id] = scalaz.Scalaz.id - - @inline override def point[A](a: => A): Scalaz.Id[A] = idInstance.point(a) - - @inline override def bind[A, B](fa: Scalaz.Id[A])(f: A => Scalaz.Id[B]): Scalaz.Id[B] = - idInstance.bind(fa)(f) - @inline override def effectOf[A](a: => A): Id[A] = a @inline override def pureOf[A](a: A): Id[A] = a diff --git a/scalaz-effect/src/test/scala/effectie/scalaz/FxSpec.scala b/scalaz-effect/src/test/scala/effectie/scalaz/FxSpec.scala index a80053df..2e0174b0 100644 --- a/scalaz-effect/src/test/scala/effectie/scalaz/FxSpec.scala +++ b/scalaz-effect/src/test/scala/effectie/scalaz/FxSpec.scala @@ -201,7 +201,10 @@ object FxSpec extends Properties { actual ==== expected } - def testMonadLaws: Property = MonadSpec.testMonadLaws[Id] + def testMonadLaws: Property = { + implicit val idInstance: Monad[Id] = scalaz.Scalaz.id + MonadSpec.testMonadLaws[Id] + } } diff --git a/scalaz-effect/src/test/scala/effectie/scalaz/MonadSpec.scala b/scalaz-effect/src/test/scala/effectie/scalaz/MonadSpec.scala index 2bf398bc..61b93e79 100644 --- a/scalaz-effect/src/test/scala/effectie/scalaz/MonadSpec.scala +++ b/scalaz-effect/src/test/scala/effectie/scalaz/MonadSpec.scala @@ -2,10 +2,11 @@ package effectie.scalaz import effectie.testing.{Gens, Specs} import hedgehog.Property -import scalaz.Equal +import scalaz.{Equal, Monad} object MonadSpec { - def testMonadLaws[F[_]: Fx](implicit eqF: Equal[F[Int]]): Property = + + def testMonadLaws[F[_]: Fx: Monad](implicit eqF: Equal[F[Int]]): Property = Specs .monadLaws .laws[F]( diff --git a/test4cats/src/main/scala/effectie/testing/cats/MonadSpec.scala b/test4cats/src/main/scala/effectie/testing/cats/MonadSpec.scala index 78285b18..76616c56 100644 --- a/test4cats/src/main/scala/effectie/testing/cats/MonadSpec.scala +++ b/test4cats/src/main/scala/effectie/testing/cats/MonadSpec.scala @@ -8,17 +8,17 @@ import hedgehog.runner._ * @since 2021-08-04 */ object MonadSpec { - def testAllLaws[F[_]: Monad](implicit eqF: Eq[F[Int]]): List[Test] = + def testAllLaws[F[_]: Monad](fName: String)(implicit eqF: Eq[F[Int]]): List[Test] = List( - property("test Monad laws - Identity", test1_Identity), - property("test Monad laws - Composition", test2_Composition), - property("test Monad laws - IdentityAp", test3_IdentityAp), - property("test Monad laws - Homomorphism", test4_Homomorphism), - property("test Monad laws - Interchange", test5_Interchange), - property("test Monad laws - CompositionAp", test6_CompositionAp), - property("test Monad laws - LeftIdentity", test7_LeftIdentity), - property("test Monad laws - RightIdentity", test8_RightIdentity), - property("test Monad laws - Associativity", test9_Associativity), + property(s"test Monad laws for $fName - Identity", test1_Identity), + property(s"test Monad laws for $fName - Composition", test2_Composition), + property(s"test Monad laws for $fName - IdentityAp", test3_IdentityAp), + property(s"test Monad laws for $fName - Homomorphism", test4_Homomorphism), + property(s"test Monad laws for $fName - Interchange", test5_Interchange), + property(s"test Monad laws for $fName - CompositionAp", test6_CompositionAp), + property(s"test Monad laws for $fName - LeftIdentity", test7_LeftIdentity), + property(s"test Monad laws for $fName - RightIdentity", test8_RightIdentity), + property(s"test Monad laws for $fName - Associativity", test9_Associativity), ) def test1_Identity[F[_]: Monad](implicit eqF: Eq[F[Int]]): Property =