Being writing a completely async library to access a remote service (using Play2.0), I\'m using Promise
and Validation
to create non-blocking call, whi
The concept you are looking for here is monad transformers. In brief, monad transformers compensate for monads not composing by allowing you to "stack" them.
You didn't mention the version of Scalaz you are using, but if you look in the scalaz-seven branch, you'll find ValidationT. This can be used to wrap any F[Validation[E, A]]
into a ValidationT[F, E, A]
, where in your case F = Promise
. If you change f
and g
to return ValidationT
, then you can leave your code as
for {
x ← f(a)
y ← g(b)
} yield y
This will give you a ValidationT[Promise, E, B]
as a result.