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

Added CommutativeMonoid for Option to scope #3463

Merged
merged 2 commits into from
Jun 11, 2020
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cats.kernel
package laws

import cats.kernel.instances.all._
import cats.kernel.laws.discipline._
import cats.platform.Platform

Expand Down Expand Up @@ -148,6 +147,15 @@ class Tests extends TestsConfig with AnyFunSuiteLike with FunSuiteDiscipline wit

import KernelCheck._

test("The instances in scope are not ambiguous") {
implicitly[Monoid[Option[String]]]
implicitly[Semigroup[Option[String]]]
implicitly[Monoid[Option[Int]]]
implicitly[Semigroup[Option[Int]]]
implicitly[CommutativeSemigroup[Option[Int]]]
implicitly[CommutativeMonoid[Option[Int]]]
}

{
// needed for Cogen[Map[...]]
implicit val ohe: Ordering[HasEq[Int]] = Ordering.by[HasEq[Int], Int](_.a)
Expand Down
12 changes: 8 additions & 4 deletions kernel/src/main/scala/cats/kernel/Semigroup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ object Semigroup

implicit def catsKernelMonoidForString: Monoid[String] = cats.kernel.instances.string.catsKernelStdMonoidForString

implicit def catsKernelMonoidForOption[A: Semigroup]: Monoid[Option[A]] =
cats.kernel.instances.option.catsKernelStdMonoidForOption[A]
implicit def catsKernelMonoidForList[A]: Monoid[List[A]] = cats.kernel.instances.list.catsKernelStdMonoidForList[A]
implicit def catsKernelMonoidForVector[A]: Monoid[Vector[A]] =
cats.kernel.instances.vector.catsKernelStdMonoidForVector[A]
Expand Down Expand Up @@ -230,6 +228,8 @@ private[kernel] trait CommutativeMonoidInstances extends MonoidInstances {
cats.kernel.instances.function.catsKernelCommutativeMonoidForFunction0[A]
implicit def catsKernelCommutativeMonoidForFunction1[A, B: CommutativeMonoid]: CommutativeMonoid[A => B] =
cats.kernel.instances.function.catsKernelCommutativeMonoidForFunction1[A, B]
implicit def catsKernelCommutativeMonoidForOption[A: CommutativeSemigroup]: CommutativeMonoid[Option[A]] =
cats.kernel.instances.option.catsKernelStdCommutativeMonoidForOption[A]
}

private[kernel] trait MonoidInstances extends BandInstances {
Expand All @@ -243,7 +243,10 @@ private[kernel] trait MonoidInstances extends BandInstances {
cats.kernel.instances.sortedMap.catsKernelStdMonoidForSortedMap[K, V]
implicit def catsKernelMonoidForEither[A, B: Monoid]: Monoid[Either[A, B]] =
cats.kernel.instances.either.catsDataMonoidForEither[A, B]
implicit def catsKernelMonoidForTry[A: Monoid]: Monoid[Try[A]] = new TryMonoid[A](Monoid[A])
implicit def catsKernelMonoidForTry[A: Monoid]: Monoid[Try[A]] =
new TryMonoid[A](Monoid[A])
implicit def catsKernelMonoidForOption[A: Semigroup]: Monoid[Option[A]] =
cats.kernel.instances.option.catsKernelStdMonoidForOption[A]
}

private[kernel] trait BandInstances extends CommutativeSemigroupInstances {
Expand All @@ -267,7 +270,8 @@ private[kernel] trait SemigroupInstances {
cats.kernel.instances.function.catsKernelSemigroupForFunction1[A, B]
implicit def catsKernelSemigroupForEither[A, B: Semigroup]: Semigroup[Either[A, B]] =
cats.kernel.instances.either.catsDataSemigroupForEither[A, B]
implicit def catsKernelSemigroupForTry[A: Semigroup]: Semigroup[Try[A]] = new TrySemigroup[A](Semigroup[A])
implicit def catsKernelSemigroupForTry[A: Semigroup]: Semigroup[Try[A]] =
new TrySemigroup[A](Semigroup[A])
}

private class TryMonoid[A](A: Monoid[A]) extends TrySemigroup[A](A) with Monoid[Try[A]] {
Expand Down