Advertisement
Guest User

scalaformonad

a guest
Aug 28th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.49 KB | None | 0 0
  1. val usdQuote = Future { connection.getCurrentValue(USD) }
  2. val chfQuote = Future { connection.getCurrentValue(CHF) }
  3. val purchase = for {
  4.   usd <- usdQuote
  5.   chf <- chfQuote
  6.   if isProfitable(usd, chf)
  7. } yield connection.buy(amount, chf)
  8. purchase onSuccess {
  9.   case _ => println("Purchased " + amount + " CHF")
  10. }
  11.  
  12. // is the same as
  13.  
  14. val purchase = usdQuote flatMap {
  15.   usd =>
  16.   chfQuote
  17.     .withFilter(chf => isProfitable(usd, chf))
  18.     .map(chf => connection.buy(amount, chf))
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement