Scala Future API combinators
The Scala Future API supports a couple of Scala combinators to ease the way of extracting values from a Future or a Promise object.
Let's explore some of the useful and important Scala Future API combinators in this section:
- map
- flatMap
- recover
- filter
Let's explore Scala Future API combinators with some simple examples here:
scala> import scala.concurrent.Promise import scala.concurrent.Promise scala> import scala.concurrent.ExecutionContext.Implicits.global import scala.conct.ExecutionContext.Implicits.global scala> val cityPromise = Promise[String]() cityPromise: scala.concurrent.Promise[String] = scala.concurrent.impl.Promise$DefaultPromise@7d07e6aa scala> cityPromise.success("Hyderabad") res13: cityPromise.type = scala.concurrent.impl.Promise$DefaultPromise@7d07e6aa scala> cityPromise.future.map { value => println(value) } scala> cityPromise.future.map { value => println(value) } res16: scala.concurrent.Future[Unit] = scala.concurrent.impl...