Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Changed Validation's Semigroup instance. Again. #129

Merged
merged 1 commit into from

2 participants

@folone

Hello.
I was shown, that after merge, Validation's Semigroup instance went back to the old state, before #114. Is this an intended change, or just a copy of the old branch state?
This pull request returns the instance back, to the state, described in #114.

@purefn

This was probably an unintended change from merging the topic/either branch.

@purefn purefn merged commit ca1989d into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 10, 2012
  1. @folone
This page is out of date. Refresh to see the latest.
View
11 core/src/main/scala/scalaz/Validation.scala
@@ -218,12 +218,15 @@ sealed trait Validation[+E, +A] {
orElse(x)
/** Return the first success or if they are both success, sum them and return that success. */
- def +++[EE >: E, AA >: A](x: => Validation[EE, AA])(implicit M: Semigroup[AA]): Validation[EE, AA] =
+ def +++[EE >: E, AA >: A](x: => Validation[EE, AA])(implicit M1: Semigroup[AA], M2: Semigroup[EE]): Validation[EE, AA] =
this match {
- case Failure(_) => this
+ case Failure(a1) => x match {
+ case Failure(a2) => Failure(M2.append(a1, a2))
+ case Success(b2) => Failure(a1)
+ }
case Success(b1) => x match {
case Failure(a2) => Failure(a2)
- case Success(b2) => Success(M.append(b1, b2))
+ case Success(b2) => Success(M1.append(b1, b2))
}
}
@@ -362,7 +365,7 @@ trait ValidationInstances1 extends ValidationInstances2 {
implicit def ValidationShow[E: Show, A: Show]: Show[Validation[E, A]] =
Show.show(_.show)
- implicit def ValidationSemigroup[E, A: Semigroup]: Semigroup[Validation[E, A]] =
+ implicit def ValidationSemigroup[E: Semigroup, A: Semigroup]: Semigroup[Validation[E, A]] =
new Semigroup[Validation[E, A]] {
def append(a1: Validation[E, A], a2: => Validation[E, A]) =
a1 +++ a2
View
2  tests/src/test/scala/scalaz/ValidationTest.scala
@@ -69,7 +69,7 @@ class ValidationTest extends Spec {
def equal[E: Equal, A: Equal] = Equal[Validation[E, A]]
def order[E: Order, A: Order] = Order[Validation[E, A]]
def pointed[E] = Pointed[({type λ[α]=Validation[E, α]})#λ]
- def semigroup[E, A: Semigroup] = Semigroup[Validation[E, A]]
+ def semigroup[E: Semigroup, A: Semigroup] = Semigroup[Validation[E, A]]
def applicative[E: Semigroup] = Applicative[({type λ[α]=Validation[E, α]})#λ]
def traverse[E: Semigroup] = Traverse[({type λ[α]=Validation[E, α]})#λ]
def plus[E: Semigroup] = Plus[({type λ[α]=Validation[E, α]})#λ]
Something went wrong with that request. Please try again.