Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val usdQuote = Future { connection.getCurrentValue(USD) }
- val chfQuote = Future { connection.getCurrentValue(CHF) }
- val purchase = for {
- usd <- usdQuote
- chf <- chfQuote
- if isProfitable(usd, chf)
- } yield connection.buy(amount, chf)
- purchase onSuccess {
- case _ => println("Purchased " + amount + " CHF")
- }
- // is the same as
- val purchase = usdQuote flatMap {
- usd =>
- chfQuote
- .withFilter(chf => isProfitable(usd, chf))
- .map(chf => connection.buy(amount, chf))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement