George Leung
Sep 6, 2018 · 1 min read

Well that example is in Kotlin. They look very similar, don’t they? Maybe you should not rule out using another language. ;)

An ugly way is to pass along a in the chain, where bAsync returns a Pair(a, b). Then I can write (in Kotlin):

aFuture.compose { a ->
modifiedBAsync(a)
}.compose { (a, b) ->
cAsync(a, b)
}

You can use a “context” object for the same purpose in Java. Have a and b being fields of that class, and pass that object along the .compose/.map chain.

I have seen it done. It works, but is not very pretty.

    George Leung

    Written by

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade