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.
