mmaillot
01/12/2020, 11:56 AMloadURL().flatMap { url -> callWS(url) }.flatMap { saveResulte(url: ???, response: it) }
How can I get the url to save it in the last flatMap ? Should I use a pair in the second flatmap .flatMap { url -> callWS(url).map { Pair(it, url) } }
?Jannis
01/12/2020, 11:59 AMfx {
val url = loadURL().bind()
val resp = callWS(url).bind()
saveResult(url, resp).bind()
}
or similar depending on your code ^^Jannis
01/12/2020, 12:00 PMmmaillot
01/12/2020, 12:00 PMTry
at this momentmmaillot
01/12/2020, 12:01 PMJannis
01/12/2020, 12:03 PMIO
because Try
will probably be removed soon (we deprecated it a while ago). Anyway this works the same for any monad, but not all have an ext method called fx
so for Try
you can do Try.monad().fx.monad {...}
to get the same thingScott Christopher
01/12/2020, 12:10 PMloadURL().flatMap { url -> callWS(url).flatMap { saveResulte(url, it) } }
This allows you to close over the url
variable by calling flatMap against the result of callWS
rather than the result of the first flatMap.Jannis
01/12/2020, 12:17 PMfx
blocks leads to more readable code. It's a style thing and I am so used to fx
that I did not even think of your solution 😄
With arrow-meta those will also have the same runtime representation, but thats a few months out ^^Scott Christopher
01/12/2020, 12:20 PMfx
version toommaillot
01/12/2020, 7:10 PM