Skip to content

Commit

Permalink
Added instances and reolution tests for Id. Removed unneeded type
Browse files Browse the repository at this point in the history
parameters.
  • Loading branch information
barambani committed Mar 9, 2018
1 parent e63a7e3 commit fba0f7a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/src/main/scala/cats/data/WriterT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions tests/src/test/scala/cats/tests/WriterTSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit fba0f7a

Please sign in to comment.