Skip to content

Commit

Permalink
Merge pull request #716 from mikejcurry/validated-semigroup
Browse files Browse the repository at this point in the history
Adds Semigroup for Validated
  • Loading branch information
non committed Dec 6, 2015
2 parents 48c38e5 + ed040de commit 519228a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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
4 changes: 3 additions & 1 deletion tests/src/test/scala/cats/tests/ValidatedTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class ValidatedTests extends CatsSuite {
checkAll("Validated[String, Int]", OrderLaws[Validated[String, Int]].order)
checkAll("Order[Validated[String, Int]]", SerializableTests.serializable(Order[Validated[String, Int]]))

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

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

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

0 comments on commit 519228a

Please sign in to comment.