Skip to content

Commit

Permalink
Merge pull request #545 from liff/topic/oneand-semigroup
Browse files Browse the repository at this point in the history
Add Semigroup instance for OneAnd
  • Loading branch information
non committed Sep 27, 2015
2 parents 9bfc979 + 1817081 commit 682a394
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/data/OneAnd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 3 additions & 1 deletion tests/src/test/scala/cats/tests/OneAndTests.scala
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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]]))
}

{
Expand Down

0 comments on commit 682a394

Please sign in to comment.