From 392956d1c0a2065a9e6378a2c2285d024c305bea Mon Sep 17 00:00:00 2001 From: Luka Jacobowitz Date: Tue, 27 Mar 2018 14:27:22 -0400 Subject: [PATCH] Add Bimonad instance to NEL and NEV --- core/src/main/scala/cats/data/NonEmptyList.scala | 6 +++--- core/src/main/scala/cats/data/NonEmptyVector.scala | 6 +++--- .../src/test/scala/cats/tests/NonEmptyListSuite.scala | 9 +++------ .../test/scala/cats/tests/NonEmptyVectorSuite.scala | 11 ++++------- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/core/src/main/scala/cats/data/NonEmptyList.scala b/core/src/main/scala/cats/data/NonEmptyList.scala index 43217d0bc4..d64f06d9cb 100644 --- a/core/src/main/scala/cats/data/NonEmptyList.scala +++ b/core/src/main/scala/cats/data/NonEmptyList.scala @@ -463,9 +463,9 @@ object NonEmptyList extends NonEmptyListInstances { private[data] sealed abstract class NonEmptyListInstances extends NonEmptyListInstances0 { implicit val catsDataInstancesForNonEmptyList: SemigroupK[NonEmptyList] with Reducible[NonEmptyList] - with Comonad[NonEmptyList] with NonEmptyTraverse[NonEmptyList] with Monad[NonEmptyList] = - new NonEmptyReducible[NonEmptyList, List] with SemigroupK[NonEmptyList] with Comonad[NonEmptyList] - with Monad[NonEmptyList] with NonEmptyTraverse[NonEmptyList] { + with Bimonad[NonEmptyList] with NonEmptyTraverse[NonEmptyList] = + new NonEmptyReducible[NonEmptyList, List] with SemigroupK[NonEmptyList] with Bimonad[NonEmptyList] + with NonEmptyTraverse[NonEmptyList] { def combineK[A](a: NonEmptyList[A], b: NonEmptyList[A]): NonEmptyList[A] = a concatNel b diff --git a/core/src/main/scala/cats/data/NonEmptyVector.scala b/core/src/main/scala/cats/data/NonEmptyVector.scala index 038a6268f0..d0db284d52 100644 --- a/core/src/main/scala/cats/data/NonEmptyVector.scala +++ b/core/src/main/scala/cats/data/NonEmptyVector.scala @@ -234,9 +234,9 @@ final class NonEmptyVector[+A] private (val toVector: Vector[A]) extends AnyVal private[data] sealed abstract class NonEmptyVectorInstances { implicit val catsDataInstancesForNonEmptyVector: SemigroupK[NonEmptyVector] with Reducible[NonEmptyVector] - with Comonad[NonEmptyVector] with NonEmptyTraverse[NonEmptyVector] with Monad[NonEmptyVector] = - new NonEmptyReducible[NonEmptyVector, Vector] with SemigroupK[NonEmptyVector] with Comonad[NonEmptyVector] - with Monad[NonEmptyVector] with NonEmptyTraverse[NonEmptyVector] { + with Bimonad[NonEmptyVector] with NonEmptyTraverse[NonEmptyVector] = + new NonEmptyReducible[NonEmptyVector, Vector] with SemigroupK[NonEmptyVector] with Bimonad[NonEmptyVector] + with NonEmptyTraverse[NonEmptyVector] { def combineK[A](a: NonEmptyVector[A], b: NonEmptyVector[A]): NonEmptyVector[A] = a concatNev b diff --git a/tests/src/test/scala/cats/tests/NonEmptyListSuite.scala b/tests/src/test/scala/cats/tests/NonEmptyListSuite.scala index a4fd14f36f..578036773d 100644 --- a/tests/src/test/scala/cats/tests/NonEmptyListSuite.scala +++ b/tests/src/test/scala/cats/tests/NonEmptyListSuite.scala @@ -6,7 +6,7 @@ import cats.kernel.laws.discipline.{SemigroupTests, OrderTests, PartialOrderTest import cats.data.{NonEmptyList, NonEmptyVector} import cats.data.NonEmptyList.ZipNonEmptyList import cats.laws.discipline.arbitrary._ -import cats.laws.discipline.{CommutativeApplyTests, ComonadTests, NonEmptyTraverseTests, MonadTests, ReducibleTests, SemigroupKTests, SerializableTests} +import cats.laws.discipline.{CommutativeApplyTests, BimonadTests, NonEmptyTraverseTests, ReducibleTests, SemigroupKTests, SerializableTests} class NonEmptyListSuite extends CatsSuite { // Lots of collections here.. telling ScalaCheck to calm down a bit @@ -21,17 +21,14 @@ class NonEmptyListSuite extends CatsSuite { checkAll("NonEmptyList[Int]", ReducibleTests[NonEmptyList].reducible[Option, Int, Int]) checkAll("Reducible[NonEmptyList]", SerializableTests.serializable(Reducible[NonEmptyList])) - checkAll("NonEmptyList[Int]", MonadTests[NonEmptyList].monad[Int, Int, Int]) - checkAll("Monad[NonEmptyList[A]]", SerializableTests.serializable(Monad[NonEmptyList])) - checkAll("NonEmptyList[Int]", SemigroupKTests[NonEmptyList].semigroupK[Int]) checkAll("SemigroupK[NonEmptyList[A]]", SerializableTests.serializable(SemigroupK[NonEmptyList])) checkAll("NonEmptyList[Int]", SemigroupTests[NonEmptyList[Int]].semigroup) checkAll("Semigroup[NonEmptyList[Int]]", SerializableTests.serializable(Semigroup[NonEmptyList[Int]])) - checkAll("NonEmptyList[Int]", ComonadTests[NonEmptyList].comonad[Int, Int, Int]) - checkAll("Comonad[NonEmptyList]", SerializableTests.serializable(Comonad[NonEmptyList])) + checkAll("NonEmptyList[Int]", BimonadTests[NonEmptyList].bimonad[Int, Int, Int]) + checkAll("Bimonad[NonEmptyList]", SerializableTests.serializable(Bimonad[NonEmptyList])) checkAll("NonEmptyList[ListWrapper[Int]]", EqTests[NonEmptyList[ListWrapper[Int]]].eqv) checkAll("Eq[NonEmptyList[ListWrapper[Int]]]", SerializableTests.serializable(Eq[NonEmptyList[ListWrapper[Int]]])) diff --git a/tests/src/test/scala/cats/tests/NonEmptyVectorSuite.scala b/tests/src/test/scala/cats/tests/NonEmptyVectorSuite.scala index 7554b7664a..55b3798b40 100644 --- a/tests/src/test/scala/cats/tests/NonEmptyVectorSuite.scala +++ b/tests/src/test/scala/cats/tests/NonEmptyVectorSuite.scala @@ -8,7 +8,7 @@ import cats.data.NonEmptyVector.ZipNonEmptyVector import cats.kernel.laws.discipline.{SemigroupTests, EqTests} import cats.data.NonEmptyVector -import cats.laws.discipline.{CommutativeApplyTests, ComonadTests, SemigroupKTests, FoldableTests, SerializableTests, NonEmptyTraverseTests, ReducibleTests, MonadTests} +import cats.laws.discipline.{CommutativeApplyTests, BimonadTests, SemigroupKTests, FoldableTests, SerializableTests, NonEmptyTraverseTests, ReducibleTests} import cats.laws.discipline.arbitrary._ import scala.util.Properties @@ -47,15 +47,12 @@ class NonEmptyVectorSuite extends CatsSuite { implicitly[Functor[NonEmptyVector]] implicitly[Monad[NonEmptyVector]] implicitly[Comonad[NonEmptyVector]] + implicitly[Bimonad[NonEmptyVector]] - checkAll("NonEmptyVector[Int]", ComonadTests[NonEmptyVector].comonad[Int, Int, Int]) - checkAll("Comonad[NonEmptyVector]", SerializableTests.serializable(Comonad[NonEmptyVector])) - - - checkAll("NonEmptyVector[Int]", MonadTests[NonEmptyVector].monad[Int, Int, Int]) - checkAll("Monad[NonEmptyVector]", SerializableTests.serializable(Monad[NonEmptyVector])) + checkAll("NonEmptyVector[Int]", BimonadTests[NonEmptyVector].bimonad[Int, Int, Int]) + checkAll("Bimonad[NonEmptyVector]", SerializableTests.serializable(Bimonad[NonEmptyVector])) test("size is consistent with toList.size") {