Suppose I've got foo: A => Try[B] and want to run it asynchronously with Future, e.g.:
import scala.util.Try
import scala.concurrent.{Future, ExecutionContext}
def foo(s: String): Try[Int] = Try(s.toInt)
def futureFoo(s: String)(implicit ec: ExecutionContext): Future[Int] = Future(foo(s).get)
Since I don't like using get method I am rewriting futureFoo like this:
def futureFoo(s: String)(implicit ec: ExecutionContext): Future[Int] =
Future(foo(s)).flatMap(Future.fromTry)
Does it make sense? Is there any helper function I missed that does exactly that?