From 688eff6a22a6d9e185698ff7fe20132e70fb6620 Mon Sep 17 00:00:00 2001 From: wedens Date: Thu, 18 May 2017 21:27:48 +0700 Subject: [PATCH] MonadTrans instance for RWST; fix MonadTrans test for StateT --- .../scala/cats/data/ReaderWriterStateT.scala | 16 +++++++--------- .../cats/tests/ReaderWriterStateTTests.scala | 13 +++++++++++-- .../src/test/scala/cats/tests/StateTTests.scala | 9 +++++---- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/core/src/main/scala/cats/data/ReaderWriterStateT.scala b/core/src/main/scala/cats/data/ReaderWriterStateT.scala index ac04862f8c..3813094ac0 100644 --- a/core/src/main/scala/cats/data/ReaderWriterStateT.scala +++ b/core/src/main/scala/cats/data/ReaderWriterStateT.scala @@ -338,9 +338,9 @@ private[data] sealed trait RWSTInstances extends RWSTInstances1 { implicit def L: Monoid[L] = L0 } - implicit def catsDataLiftForRWST[E, S, L]( - implicit L0: Monoid[L]): TransLift.Aux[ReaderWriterStateT[?[_], E, S, L, ?], Applicative] = - new RWSTTransLift[E, S, L] { + implicit def catsDataMonadTransForRWST[E, S, L]( + implicit L0: Monoid[L]): MonadTrans[ReaderWriterStateT[?[_], E, S, L, ?]] = + new RWSTMonadTrans[E, S, L] { implicit def L: Monoid[L] = L0 } } @@ -487,12 +487,10 @@ private[data] sealed trait RWSTMonadState[F[_], E, S, L] def set(s: S): ReaderWriterStateT[F, E, S, L, Unit] = ReaderWriterStateT.set(s) } -private[data] sealed trait RWSTTransLift[E, S, L] extends TransLift[ReaderWriterStateT[?[_], E, S, L, ?]] { +private[data] sealed trait RWSTMonadTrans[E, S, L] extends MonadTrans[ReaderWriterStateT[?[_], E, S, L, ?]] { implicit def L: Monoid[L] - type TC[F[_]] = Applicative[F] - - def liftT[F[_], A](fa: F[A])(implicit F: Applicative[F]): ReaderWriterStateT[F, E, S, L, A] = - ReaderWriterStateT.lift(fa) + def liftT[M[_]: Monad, A](ma: M[A]): ReaderWriterStateT[M, E, S, L, A] = + ReaderWriterStateT.lift(ma) } private[data] sealed trait RWSTSemigroupK[F[_], E, S, L] extends SemigroupK[ReaderWriterStateT[F, E, S, L, ?]] { @@ -507,7 +505,7 @@ private[data] sealed trait RWSTSemigroupK[F[_], E, S, L] extends SemigroupK[Read private[data] sealed trait RWSTMonadCombine[F[_], E, S, L] extends MonadCombine[ReaderWriterStateT[F, E, S, L, ?]] with RWSTMonad[F, E, S, L] - with RWSTSemigroupK[F, E, S, L] with RWSTTransLift[E, S, L] { + with RWSTSemigroupK[F, E, S, L] with RWSTMonadTrans[E, S, L] { implicit def F: MonadCombine[F] override def G: MonadCombine[F] = F diff --git a/tests/src/test/scala/cats/tests/ReaderWriterStateTTests.scala b/tests/src/test/scala/cats/tests/ReaderWriterStateTTests.scala index 3239ba3a0e..7cb7fe1ce3 100644 --- a/tests/src/test/scala/cats/tests/ReaderWriterStateTTests.scala +++ b/tests/src/test/scala/cats/tests/ReaderWriterStateTTests.scala @@ -338,12 +338,21 @@ class ReaderWriterStateTTests extends CatsSuite { } { - implicit def F = ListWrapper.monad - implicit def S = ListWrapper.semigroupK + implicit val F = ListWrapper.monad + implicit val S = ListWrapper.semigroupK checkAll("ReaderWriterStateT[ListWrapper, String, Int, String, Int]", SemigroupKTests[ReaderWriterStateT[ListWrapper, String, Int, String, ?]].semigroupK[Int]) } + + { + implicit val F = ListWrapper.monad + + checkAll("MonadTrans[ReaderWriterStateT[?[_], String, Int, String, ?]]", + MonadTransTests[ReaderWriterStateT[?[_], String, Int, String, ?]].monadTrans[ListWrapper, Int, Int]) + checkAll("MonadTrans[ReaderWriterStateT[?[_], String, Int, String, ?]]", + SerializableTests.serializable(MonadTrans[ReaderWriterStateT[?[_], String, Int, String, ?]])) + } } object ReaderWriterStateTTests { diff --git a/tests/src/test/scala/cats/tests/StateTTests.scala b/tests/src/test/scala/cats/tests/StateTTests.scala index 61e4ba61d3..63c45cb1d6 100644 --- a/tests/src/test/scala/cats/tests/StateTTests.scala +++ b/tests/src/test/scala/cats/tests/StateTTests.scala @@ -235,7 +235,8 @@ class StateTTests extends CatsSuite { checkAll("StateT[ListWrapper, Int, Int]", MonadTests[StateT[ListWrapper, Int, ?]].monad[Int, Int, Int]) checkAll("Monad[StateT[ListWrapper, Int, ?]]", SerializableTests.serializable(Monad[StateT[ListWrapper, Int, ?]])) - checkAll("MonadTrans[EitherT[?[_], String, ?]]", MonadTransTests[EitherT[?[_], String, ?]].monadTrans[ListWrapper, Int, Int]) + checkAll("MonadTrans[StateT[?[_], Int, ?]]", MonadTransTests[StateT[?[_], String, ?]].monadTrans[ListWrapper, Int, Int]) + checkAll("MonadTrans[StateT[?[_], Int, ?]]", SerializableTests.serializable(MonadTrans[StateT[?[_], Int, ?]])) Monad[StateT[ListWrapper, Int, ?]] FlatMap[StateT[ListWrapper, Int, ?]] @@ -248,8 +249,8 @@ class StateTTests extends CatsSuite { { // F has a Monad and a SemigroupK - implicit def F = ListWrapper.monad - implicit def S = ListWrapper.semigroupK + implicit val F = ListWrapper.monad + implicit val S = ListWrapper.semigroupK checkAll("StateT[ListWrapper, Int, Int]", SemigroupKTests[StateT[ListWrapper, Int, ?]].semigroupK[Int]) checkAll("SemigroupK[StateT[ListWrapper, Int, ?]]", SerializableTests.serializable(SemigroupK[StateT[ListWrapper, Int, ?]])) @@ -257,7 +258,7 @@ class StateTTests extends CatsSuite { { // F has a MonadCombine - implicit def F = ListWrapper.monadCombine + implicit val F = ListWrapper.monadCombine checkAll("StateT[ListWrapper, Int, Int]", MonadCombineTests[StateT[ListWrapper, Int, ?]].monadCombine[Int, Int, Int]) checkAll("MonadCombine[StateT[ListWrapper, Int, ?]]", SerializableTests.serializable(MonadCombine[StateT[ListWrapper, Int, ?]]))