List[Try[T]] to Try[List[T]] in Scala

前端 未结 4 1074
天涯浪人
天涯浪人 2021-01-20 22:04

I would like to know how to convert a List[Try[T]] into Try[List[T]] in Scala?

I have tried using an accumulator and folding right but it do

4条回答
  •  迷失自我
    2021-01-20 22:06

    Try(list.map(_.get))
    

    This will return only the first failure, so you need something more complicated if you want to catch all the failures in the list.

提交回复
热议问题