Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.63 KB | None | 0 0
  1.  
  2. import scala.concurrent._
  3. import ExecutionContext.Implicits.global
  4. import scala.util.{Success, Failure}
  5.  
  6. object Demo {
  7.     def main(args: Array[String]){
  8.  
  9.         val b2: Future[List[Int]] = Future {
  10.             List(1,2)
  11.         }
  12.  
  13.         val c2:Future[List[Int]] = b2.map( x => x.map( _*3 ) )
  14.  
  15.         // Note how in this case the two `map` do not have the same meaning.
  16.  
  17.         c2 onComplete {
  18.           case Success(value) => println(s"Value: $value")
  19.           case Failure(t) => println("An error has occured: " + t.getMessage)
  20.         }
  21.  
  22.         // Outputs: Value: List(3, 6)
  23.  
  24.         Thread.sleep(2000)
  25.  
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement