Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bimonad instance to NEL and NEV #2219

Merged
merged 1 commit into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/src/main/scala/cats/data/NonEmptyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/cats/data/NonEmptyVector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions tests/src/test/scala/cats/tests/NonEmptyListSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]]]))
Expand Down
11 changes: 4 additions & 7 deletions tests/src/test/scala/cats/tests/NonEmptyVectorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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") {
Expand Down