It’s really easy to roll your own, especially if you don’t care about the collection type being preserved.
def traverse[A, E, B](as: Seq[A])(f: A => Either[E, B]): Either[E, Seq[B]] = Right( as.map(a => f(a) match {
case Right(b) => b
case Left(e) => return Left(e)
}))
If you do care about preserving the collection type, you can use either the 2.12 or 2.13 strategy (depending on which you use) to generalize over collections, but the logic is the same.
Rust actually has this built in to the language with the postfix ? operator (early return of error value), and I add it as a macro, so when I’m doing something like this it’s just
Right(as.map(a => f(a).?))
which is almost unbelievably easy, and so I use it ubiquitously (not just for this task).
Note that if the error case comes up very often, this isn’t the best-performing because it requires throwing and catching a stackless exception. If errors are common, you probably want to use a builder and iterator instead (so you can do the early return from a while loop, so it’s a local return without needing exceptions rather than a nonlocal return).