From fba0f7a38c59ae5c7ac8b6c43fe7765541d97f5d Mon Sep 17 00:00:00 2001 From: Filippo Mariotti Date: Fri, 9 Mar 2018 16:20:11 +0000 Subject: [PATCH] Added instances and reolution tests for Id. Removed unneeded type parameters. --- core/src/main/scala/cats/data/WriterT.scala | 14 ++++++++++++-- .../src/test/scala/cats/tests/WriterTSuite.scala | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/cats/data/WriterT.scala b/core/src/main/scala/cats/data/WriterT.scala index 73c50b22e3..da2c5bab76 100644 --- a/core/src/main/scala/cats/data/WriterT.scala +++ b/core/src/main/scala/cats/data/WriterT.scala @@ -106,13 +106,20 @@ private[data] sealed abstract class WriterTInstances extends WriterTInstances0 { implicit val F0: Monad[F] = F implicit val L0: Monoid[L] = L } + + implicit def catsDataTraverseForWriterTId[L](implicit F: Traverse[Id]): Traverse[WriterT[Id, L, ?]] = + catsDataTraverseForWriterT[Id, L] } private[data] sealed abstract class WriterTInstances0 extends WriterTInstances1 { - implicit def catsDataTraverseForWriterT[F[_], L, V](implicit F: Traverse[F]): Traverse[WriterT[F, L, ?]] = + + implicit def catsDataTraverseForWriterT[F[_], L](implicit F: Traverse[F]): Traverse[WriterT[F, L, ?]] = new WriterTTraverse[F, L] { val F0: Traverse[F] = F } + + implicit def catsDataFoldableForWriterTId[L](implicit F: Foldable[Id]): Foldable[WriterT[Id, L, ?]] = + catsDataFoldableForWriterT[Id, L] } private[data] sealed abstract class WriterTInstances1 extends WriterTInstances2 { @@ -153,7 +160,7 @@ private[data] sealed abstract class WriterTInstances1 extends WriterTInstances2 implicit def catsDataMonoidForWriterTId[L:Monoid, V:Monoid]: Monoid[WriterT[Id, L, V]] = catsDataMonoidForWriterT[Id, L, V] - implicit def catsDataFoldableForWriterT[F[_], L, V](implicit F: Foldable[F]): Foldable[WriterT[F, L, ?]] = + implicit def catsDataFoldableForWriterT[F[_], L](implicit F: Foldable[F]): Foldable[WriterT[F, L, ?]] = new WriterTFoldable[F, L]{ val F0: Foldable[F] = F } @@ -168,6 +175,9 @@ private[data] sealed abstract class WriterTInstances2 extends WriterTInstances3 implicit def catsDataSemigroupForWriterTId[L:Semigroup, V:Semigroup]: Semigroup[WriterT[Id, L, V]] = catsDataSemigroupForWriterT[Id, L, V] + + implicit def catsDataComonadForWriterTId[L](implicit F: Comonad[Id]): Comonad[WriterT[Id, L, ?]] = + catsDataComonadForWriterT[Id, L] } private[data] sealed abstract class WriterTInstances3 extends WriterTInstances4 { diff --git a/tests/src/test/scala/cats/tests/WriterTSuite.scala b/tests/src/test/scala/cats/tests/WriterTSuite.scala index 81d259303d..cb3b5acf48 100644 --- a/tests/src/test/scala/cats/tests/WriterTSuite.scala +++ b/tests/src/test/scala/cats/tests/WriterTSuite.scala @@ -373,28 +373,43 @@ class WriterTSuite extends CatsSuite { { // F has a Foldable and L has a Monoid implicit val L: Monoid[ListWrapper[Int]] = ListWrapper.monoid[Int] + Foldable[Const[String, ?]] Foldable[WriterT[Const[String, ?], ListWrapper[Int], ?]] checkAll("WriterT[Const[String, ?], ListWrapper[Int], ?]", FoldableTests[WriterT[Const[String, ?], ListWrapper[Int], ?]].foldable[Int, Int]) checkAll("Foldable[WriterT[Const[String, ?], ListWrapper[Int], ?]]", SerializableTests.serializable(Foldable[WriterT[Const[String, ?], ListWrapper[Int], ?]])) + + Foldable[Id] + Foldable[WriterT[Id, ListWrapper[Int], ?]] + Foldable[Writer[ListWrapper[Int], ?]] } { // F has a Traverse and L has a Monoid implicit val L: Monoid[ListWrapper[Int]] = ListWrapper.monoid[Int] + Traverse[Const[String, ?]] Traverse[WriterT[Const[String, ?], ListWrapper[Int], ?]] checkAll("WriterT[Const[String, ?], ListWrapper[Int], ?]", TraverseTests[WriterT[Const[String, ?], ListWrapper[Int], ?]].traverse[Int, Int, Int, Int, Option, Option]) checkAll("Traverse[WriterT[Const[String, ?], ListWrapper[Int], ?]]", SerializableTests.serializable(Traverse[WriterT[Const[String, ?], ListWrapper[Int], ?]])) + + Traverse[Id] + Traverse[WriterT[Id, ListWrapper[Int], ?]] + Traverse[Writer[ListWrapper[Int], ?]] } { // F has a Comonad and L has a Monoid implicit val L: Monoid[ListWrapper[Int]] = ListWrapper.monoid[Int] + Comonad[(String, ?)] Comonad[WriterT[(String, ?), ListWrapper[Int], ?]] checkAll("WriterT[(String, ?), ListWrapper[Int], ?]", ComonadTests[WriterT[(String, ?), ListWrapper[Int], ?]].comonad[Int, Int, Int]) checkAll("Comonad[WriterT[(String, ?), ListWrapper[Int], ?]]", SerializableTests.serializable(Comonad[WriterT[(String, ?), ListWrapper[Int], ?]])) + + Comonad[Id] + Comonad[WriterT[Id, ListWrapper[Int], ?]] + Comonad[Writer[ListWrapper[Int], ?]] } checkAll("WriterT[Option, Int, ?]", CommutativeMonadTests[WriterT[Option, Int, ?]].commutativeMonad[Int, Int, Int])