Scala: Try till first success on a list
You can do the same thing using collectFirst
in one less step:
inputs.iterator.map(foo).collectFirst { case Success(x) => x }
You want this:
inputs
.iterator // or view (anything lazy works)
.map(foo)
.find(_.isSuccess)
.map(_.get)
It returns an Option[B]
.