Skip to content

Commit

Permalink
Adds Semigroup for Validated
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejcurry committed Dec 6, 2015
1 parent 48c38e5 commit ed3f768
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/src/main/scala/cats/data/Validated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ private[data] sealed abstract class ValidatedInstances extends ValidatedInstance
}

private[data] sealed abstract class ValidatedInstances1 extends ValidatedInstances2 {

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

implicit def validatedPartialOrder[A: PartialOrder, B: PartialOrder]: PartialOrder[Validated[A,B]] =
new PartialOrder[Validated[A,B]] {
def partialCompare(x: Validated[A,B], y: Validated[A,B]): Double = x partialCompare y
Expand Down
2 changes: 2 additions & 0 deletions tests/src/test/scala/cats/tests/ValidatedTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ValidatedTests extends CatsSuite {

checkAll("Monoid[Validated[String, Int]]", GroupLaws[Validated[String, Int]].monoid)

checkAll("Semigroup[Validated[String, NonEmptyList[Int]]]", GroupLaws[Validated[String, NonEmptyList[Int]]].semigroup)

{
implicit val S = ListWrapper.partialOrder[String]
implicit val I = ListWrapper.partialOrder[Int]
Expand Down

0 comments on commit ed3f768

Please sign in to comment.