Another, more canonical way to do it might be to use the collect method, which has a signature like this:def collect[B](f: PartialFunction[A, B]) : Seq[B]which keeps only the elements for which f was defined.
myList collect {case o if p(f(o)) => f(o)}but yes, not ideal because you call f twice.That said, I reckon you can pretty much by definition filter on the input if you can filter on the output.
It is more like a complex map function might fail and I need to
skip/filter that out.
If this is happening anywhere that performance matters, you're probably better off partitioning beforehand, rather than just catching the exception.
Otherwise yeah, Try is the guy for you.
myList collect {case o if p(f(o)) => f(o)}but yes, not ideal because you call f twice.