Validation does not have a Bind defined for it.
In Scalaz 7.1.0-M5 (M6 too) Validation.flatMap
is deprecated and in an attempt at subverting the warning, it looks like the precedence of flatMap
is losing to scalaz.syntax.bind._
, which is part of the Scalaz._
import. See this commit https://github.com/scalaz/scalaz/commit/2727b2451eba2aa159f3fbb62bf92790ac99dc7a. Try adding import scalaz.Validation.FlatMap._
or importing only the things you need, e.g.
import scalaz.Validation
import scalaz.syntax.validation._
I would recommend using something besides Validation
though, as this will probably only cause you more problems in the future. See scalaz.\/
below.
This does compile with scalaz 7.0.5. Validation.flatMap
is defined in 7.0.6 so it should compile with that version too. I would not use this functionality (Validation
in for
comprehensions) in new code though.
The scalaz powers that be have gona back and forth on deprecating Validation.flatMap
for some time now. flatMap
is what allows it to work in for
comprehensions. flatMap
is deprecated in the working branch though. There is a long background on this. See https://groups.google.com/forum/#!topic/scalaz/Wnkdyhebo2w.
TLDR - Validation is not a monad. Any possible implementation of Validation.flatMap
will not match behavior of the Apply
defined for Validation
.
Use scalaz.\/
(a.k.a. disjunction) if you want to use something in for
comprehensions. If you need to accumulate errors, the reason to use Validation
over \/
, convert to Validation
and then back to \/
.