Comment

Comment by runT1ME

This is what monadic syntax is for. You can do the following for any Future in scala:

    for {
       resa <- asyncCall(1)
       resb <- asyncCall(2)
       resc <- asyncCall(3)
    } yield new Obj(resa, resb, resc)
which just gets rewritten to

    asyncCall(1).flatMap(resa => asyncCall(2).flaMap(resb =>
           asyncCall(3).map(resc => new Obj(resa, resb, resc))))
This doesn't just work for futures, it works for any monad. This is super amazingly useful. Also, query syntax for LINQ in C#/F# can support this too.
parent runT1ME 10 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton