From 5eceefc04c2e5974a4c499589b0b78d09f568865 Mon Sep 17 00:00:00 2001 From: Olli Helenius Date: Sun, 27 Sep 2015 18:34:23 +0300 Subject: [PATCH 1/2] Add Semigroup instance for OneAnd --- core/src/main/scala/cats/data/OneAnd.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/scala/cats/data/OneAnd.scala b/core/src/main/scala/cats/data/OneAnd.scala index ff169f9e8f..cfa47b1baa 100644 --- a/core/src/main/scala/cats/data/OneAnd.scala +++ b/core/src/main/scala/cats/data/OneAnd.scala @@ -103,6 +103,9 @@ trait OneAndInstances extends OneAndLowPriority1 { a combine b } + implicit def oneAndSemigroup[F[_]: MonadCombine, A]: Semigroup[OneAnd[A, F]] = + oneAndSemigroupK.algebra + implicit def oneAndFoldable[F[_]](implicit foldable: Foldable[F]): Foldable[OneAnd[?,F]] = new Foldable[OneAnd[?,F]] { override def foldLeft[A, B](fa: OneAnd[A, F], b: B)(f: (B, A) => B): B = From 181708120c8119b1e8be5a6f600c33d6cce21329 Mon Sep 17 00:00:00 2001 From: Olli Helenius Date: Sun, 27 Sep 2015 19:51:13 +0300 Subject: [PATCH 2/2] Add tests for Semigroup instance of OneAnd --- tests/src/test/scala/cats/tests/OneAndTests.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/src/test/scala/cats/tests/OneAndTests.scala b/tests/src/test/scala/cats/tests/OneAndTests.scala index 01bf399ee6..3e1c94d916 100644 --- a/tests/src/test/scala/cats/tests/OneAndTests.scala +++ b/tests/src/test/scala/cats/tests/OneAndTests.scala @@ -1,7 +1,7 @@ package cats package tests -import algebra.laws.OrderLaws +import algebra.laws.{GroupLaws, OrderLaws} import cats.data.{NonEmptyList, OneAnd} import cats.laws.discipline.{ComonadTests, FunctorTests, SemigroupKTests, FoldableTests, MonadTests, SerializableTests} @@ -24,7 +24,9 @@ class OneAndTests extends CatsSuite { { implicit val monadCombine = ListWrapper.monadCombine checkAll("OneAnd[Int, ListWrapper]", SemigroupKTests[OneAnd[?, ListWrapper]].semigroupK[Int]) + checkAll("OneAnd[Int, List]", GroupLaws[OneAnd[Int, List]].semigroup) checkAll("SemigroupK[OneAnd[A, ListWrapper]]", SerializableTests.serializable(SemigroupK[OneAnd[?, ListWrapper]])) + checkAll("Semigroup[NonEmptyList[Int]]", SerializableTests.serializable(Semigroup[OneAnd[Int, List]])) } {