scala - How to convert Iterable[Try[U]] filter successed to Iterable[U]? -
i tried
val tryvalues : iterable[try[int]] = ... val successvalues = tryvalues.filter(_.issuccess).map(_.get)
but compiler give warning map may throw exception. there way free of warning?
another option here, if don't care log fails flatmap
using tooption
on try
. so:
val successvalues = tryvalues.flatmap(_.tooption)
Comments
Post a Comment