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

Adds Semigroup for Xor #717

Merged
merged 2 commits into from
Dec 7, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 6 additions & 0 deletions core/src/main/scala/cats/data/Xor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ private[data] sealed abstract class XorInstances extends XorInstances1 {
}

private[data] sealed abstract class XorInstances1 extends XorInstances2 {

implicit def xorSemigroup[A, B](implicit A: Semigroup[A], B: Semigroup[B]): Semigroup[A Xor B] =
new Semigroup[A Xor B] {
def combine(x: A Xor B, y: A Xor B): A Xor B = x combine y
}

implicit def xorPartialOrder[A: PartialOrder, B: PartialOrder]: PartialOrder[A Xor B] = new PartialOrder[A Xor B] {
def partialCompare(x: A Xor B, y: A Xor B): Double = x partialCompare y
override def eqv(x: A Xor B, y: A Xor B): Boolean = x === y
Expand Down
7 changes: 4 additions & 3 deletions tests/src/test/scala/cats/tests/XorTests.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cats
package tests

import cats.data.{Xor, XorT}
import cats.data.{NonEmptyList, Xor, XorT}
import cats.data.Xor._
import cats.laws.discipline.arbitrary.xorArbitrary
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.{BifunctorTests, TraverseTests, MonadErrorTests, SerializableTests}
import algebra.laws.{GroupLaws, OrderLaws}
import org.scalacheck.{Arbitrary, Gen}
Expand All @@ -12,7 +12,8 @@ import org.scalacheck.Arbitrary._
import scala.util.Try

class XorTests extends CatsSuite {
checkAll("Xor[String, Int]", GroupLaws[Xor[String, Int]].monoid)
checkAll("Monoid[Xor[String, Int]]", GroupLaws[Xor[String, Int]].monoid)
checkAll("Semigroup[Xor[String, NonEmptyList[Int]]]", GroupLaws[Xor[String, NonEmptyList[Int]]].semigroup)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: monoid/semigroup are already included in the test names, so I think the convention has been to not include Monoid/Semigroup in the string argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - I can certainly change this. For some reason I'd thought I'd seen a mix of these versions, but I see now it was likely my eyes deceiving me. :-)


implicit val eq0 = XorT.xorTEq[Xor[String, ?], String, Int]

Expand Down