http://docs.scala-lang.org/overviews/core/futures.html
From oficial tutorials, regarding map:
One of the basic combinators is map, which, given a future and a
mapping function for the value of the future, produces a new future
that is completed with the mapped value once the original future is
successfully completed.
Regarding flat map.
The flatMap method takes a function that maps the value to a new future g, and then returns a future which is completed once g is completed.
So in your case since you just want to convert response to some other value, you need a map function, which would map result of your future to String.
val next: Future[String] = (chunk.map(_.\("paging").\("next").as[String]))
Next value here is a either failure from chunk or result of mapping chunk js value to String.
If you would have some additional asynchronous calculations, like
def calculations: (x: String): Future[Int] = ...
val next: Future[Int] = chunk.flatMap(js=> {
val x = js.\("paging").\("next").as[String]
calculations(x)
})
You would need to use flatMap, combining two dependent asynchronous futures in one. Next value here is a result of calculations function, applied to result returned from chunk.
mapwraps the result of the anonymous function in another future,flatMapinstead needs you to wrap the result in a future, in both cases the return type isFuture[T]. - Ende Neunext.map(otherFunctionThatTakesAString)- Ryan