Validation's Semigroup instance #101

merged 1 commit into from Jul 10, 2012


None yet

2 participants

folone commented Jul 9, 2012

I've noticed, that Validation's Semigroup instance requires that only the left (Failure) element is a Semigroup. At the same time, Validation itself has an append method, which requires both elements to be Semigroups. I've changed the default instance to use that method. The old definition is still used to generate FailProjection's Semigroup instance and is renamed to validationSemigroupFail. Here's how this works now:

scala> val success1 = 1.success[String]
success1: scalaz.Validation[String,Int] = Success(1)

scala> val success2 = 2.success[String]
success2: scalaz.Validation[String,Int] = Success(2)

scala> val success3 = 1.success[String].fail
success3: scalaz.FailProjection[String,Int] = scalaz.Validation$$anon$18@59bdcda

scala> val success4 = 2.success[String].fail
success4: scalaz.FailProjection[String,Int] = scalaz.Validation$$anon$18@655554a8

scala> success1 |+| success2
res0: scalaz.Validation[String,Int] = Success(3) // was: Success(1)

scala> success3 |+| success4
res1: scalaz.FailProjection[String,Int] = scalaz.Validation$$anon$18@5f6bfe9c

scala> .validation
res2: scalaz.Validation[String,Int] = Success(1)

Does this make sense?

Georgii Leontiev Changed Validation's Semigroup instance to use both Failure's and Suc…
…cess' Semigroup instances.
@tonymorris tonymorris merged commit 4b086d2 into scalaz:scalaz-seven Jul 10, 2012

Sorry I had to roll back this pull request as it broke compilation. Can you please resubmit?

folone commented Jul 17, 2012

@tonymorris Sorry for that. I've created #103.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment