Skip to content
This repository

Changed Validation's Semigroup instance. Again. #129

Merged
merged 1 commit into from over 1 year ago

2 participants

George Leontiev Richard Wallace
George Leontiev

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.

Richard Wallace
Collaborator

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

Richard Wallace purefn merged commit ca1989d into from August 10, 2012
Richard Wallace purefn closed this August 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 10, 2012
George Leontiev Changed Validation's Semigroup instance. b6ce05d
This page is out of date. Refresh to see the latest.
11  core/src/main/scala/scalaz/Validation.scala
@@ -218,12 +218,15 @@ sealed trait Validation[+E, +A] {
218 218
     orElse(x)
219 219
 
220 220
   /** Return the first success or if they are both success, sum them and return that success. */
221  
-  def +++[EE >: E, AA >: A](x: => Validation[EE, AA])(implicit M: Semigroup[AA]): Validation[EE, AA] =
  221
+  def +++[EE >: E, AA >: A](x: => Validation[EE, AA])(implicit M1: Semigroup[AA], M2: Semigroup[EE]): Validation[EE, AA] =
222 222
     this match {
223  
-      case Failure(_) => this
  223
+      case Failure(a1) => x match {
  224
+        case Failure(a2) => Failure(M2.append(a1, a2))
  225
+        case Success(b2) => Failure(a1)
  226
+      }
224 227
       case Success(b1) => x match {
225 228
         case Failure(a2) => Failure(a2)
226  
-        case Success(b2) => Success(M.append(b1, b2))
  229
+        case Success(b2) => Success(M1.append(b1, b2))
227 230
       }
228 231
     }
229 232
 
@@ -362,7 +365,7 @@ trait ValidationInstances1 extends ValidationInstances2 {
362 365
   implicit def ValidationShow[E: Show, A: Show]: Show[Validation[E, A]] =
363 366
     Show.show(_.show)
364 367
 
365  
-  implicit def ValidationSemigroup[E, A: Semigroup]: Semigroup[Validation[E, A]] =
  368
+  implicit def ValidationSemigroup[E: Semigroup, A: Semigroup]: Semigroup[Validation[E, A]] =
366 369
     new Semigroup[Validation[E, A]] {
367 370
       def append(a1: Validation[E, A], a2: => Validation[E, A]) =
368 371
         a1 +++ a2
2  tests/src/test/scala/scalaz/ValidationTest.scala
@@ -69,7 +69,7 @@ class ValidationTest extends Spec {
69 69
     def equal[E: Equal, A: Equal] = Equal[Validation[E, A]]
70 70
     def order[E: Order, A: Order] = Order[Validation[E, A]]
71 71
     def pointed[E] = Pointed[({type λ[α]=Validation[E, α]})#λ]
72  
-    def semigroup[E, A: Semigroup] = Semigroup[Validation[E, A]]
  72
+    def semigroup[E: Semigroup, A: Semigroup] = Semigroup[Validation[E, A]]
73 73
     def applicative[E: Semigroup] = Applicative[({type λ[α]=Validation[E, α]})#λ]
74 74
     def traverse[E: Semigroup] = Traverse[({type λ[α]=Validation[E, α]})#λ]
75 75
     def plus[E: Semigroup] = Plus[({type λ[α]=Validation[E, α]})#λ]
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.