Placeholder object for value that may not yet exist, revolve around ExecutionContext which has access to a thread pool similar to Executor design pattern, commonly you map over it
// delegate the execution of fatMatrix.inverse() to an ExecutionContext and embody the result of the computation in inverseFuture.val inverseFuture: Future[Matrix] = Future { fatMatrix.inverse() // non-blocking long lasting computation}(executionContext)implicitval ec: ExecutionContext = ...val inverseFuture : Future[Matrix] = Future { fatMatrix.inverse()} // ec is implicitly passed
flatmap -> like map but ft returns a future not a value, used to call ft's that return future on value yet to be computed
for loop basically allows several flatMaps then a final map yielding a Future value
futures start running immediately on seperate threads and main thread runs through this without blocking
resultF is just a Future that waits for component parts to finish before completing itself
val threeF = Future(3)val fourF = Future(4)val fiveF = Future(5)val resultF =for{ three <- threeF four <- fourF five <- fiveF}yield{ three * four * five}//EQUALSval resultF = threeF.flatMap(three => fourF.flatMap(four => fiveF.map(five => three * four * five)))