/** Bind through the success of this validation. */@deprecated("flatMap does not accumulate errors, use `\\/` instead", "7.1")def flatMap[EE >: E, B](f: A => Validation[EE, B]): Validation[EE, B] =this match {case Success(a) => f(a)case e @ Failure(_) => e}Since I do large usage of this feature, I am interested in understanding more, but I am not able to find \\/ method.Where is it defined?BestEdmondo
/** Bind through the success of this validation. */@deprecated("flatMap does not accumulate errors, use `\\/` instead", "7.1")def flatMap[EE >: E, B](f: A => Validation[EE, B]): Validation[EE, B] =this match {case Success(a) => f(a)case e @ Failure(_) => e}
Either:
/** Bind through the right of this disjunction. */def flatMap[AA >: A, D](g: B => (AA \/ D)): (AA \/ D) =this match {case a @ -\/(_) => acase \/-(b) => g(b)}Could you please explain me the difference?
This is kind of strange. I can understand why Validation is not a monad but there's no reason not to keep the flatMap method around.
--
You received this message because you are subscribed to the Google Groups "scalaz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaz+un...@googlegroups.com.
To post to this group, send email to sca...@googlegroups.com.
Visit this group at http://groups.google.com/group/scalaz.
For more options, visit https://groups.google.com/groups/opt_out.
So that it cannot be used in a for comprehension.
-- Tony Morris http://tmorris.net/
My frequent usage is in chaining together several "gets" where each line in the for-comprehension returns a raw object, an Option or a scalar value and for most uses, each line is dependent on the previous one. The for-comprehension allows me to sequence them. The overall function should return a Validation[String, MyObjectType] if one of the "gets" fails.
-- Stephen Compall "^aCollection allSatisfy: [:each|aCondition]": less is better |
This function should probably return String \/ MyObjectType instead; this structure has the behavior you are describing.
Validation is only good for you insofar as its behavior gives you the results you expect. Consider your "error message", String. If I have two failures from your code, s1 and s2, is (s1 + s2) also an "error message"?
Validation and \/ have methods on them to run functions as if they are the other.
Why is it bad if validation can be used in a for comprehension? Just because you prefer that syntax be used for types that are monads?
Validation is isomorphic to Either, and if it it didn't mess with implicit lookup, we could define both a monad and an applicative (with different meanings) for the same type. This overlap happens a lot - streams have a 'zippy' applicative and a sequencing monad with different meanings.
So, I'd like to hear an actual argument. The existing flatMap is convenient at times. Getting rid of flatMap will break existing code, and what are you going to call that function if not flatMap?
Why is it bad if validation can be used in a for comprehension? Just because you prefer that syntax be used for types that are monads?
Validation is isomorphic to Either, and if it it didn't mess with implicit lookup, we could define both a monad and an applicative (with different meanings) for the same type. This overlap happens a lot - streams have a 'zippy' applicative and a sequencing monad with different meanings.
So, I'd like to hear an actual argument. The existing flatMap is convenient at times. Getting rid of flatMap will break existing code, and what are you going to call that
function if not flatMap?
Yes it is possible to have two different instances in scope, with different implicit priority. I don't think we should do this though. I'd rather we just undeprecate flatMap.
I think, not strongly, that it is a reasonable expectation that these two programs are the same: <for-comprehension/applicative versions elided>
I think the type system should also enforce the requirement of Monad. Therefore, Validation in a for-comprehension should yield a type error.
-- Tony Morris http://tmorris.net/