Is it possible to use Scalaz' traverse
and traverseU
with Either
instead of Option
?
For the following code:
val list = List(1, 2, 3)
def f(i: Int): Either[Int, String] =
if (i > 2) Left(i)
else Right("must be lower than 3")
I want to traverse list
with f
and either return the first Right(msg)
if there is one or more failure, or Left(list)
if everything went right.
Is there any reason why you're not using
Validation
andNonEmptyList
by scalaz?You can easily do something like
If you instead want to fail on the first error, you can use
\/
, aka the scalaz version ofEither
which is isomorphic toscala.Either
but right-biased