How does the map
operation from WebClient
do the mapping?
Given that example:
client.get()
.uri("/quotes").accept(MediaType.TEXT_EVENT_STREAM)
.retrieve()
.bodyToFlux(Quote.class);
When i want to convert Quote
on the fly to BetterQuote
for example:
client.get()
.uri("/quotes").accept(MediaType.TEXT_EVENT_STREAM)
.retrieve()
.bodyToFlux(Quote.class)
.map(this::toBetterQuote);
The question here is:
Will all Quotes
be fetched from a given API and then (if all are there) the map()
will happen?
Or does the map()
starts to happen immediatly when the first Quotes
are coming in?
So will this iterate only once the whole Quotes
?
Iterable<BetterQuote> betterQuotes = client.get()
.uri("/quotes").accept(MediaType.TEXT_EVENT_STREAM)
.retrieve()
.bodyToFlux(Quote.class)
.map(this::toBetterQuote)
.toIterable();
Whereas this iterates twice?
Iterable<Quote> betterQuotes = client.get()
.uri("/quotes").accept(MediaType.TEXT_EVENT_STREAM)
.retrieve()
.bodyToFlux(Quote.class)
.toIterable();
Iterable<BetterQuote> moreBetter = betterQuotes.map(this::mapToBetterQuotes)