ayush prashar
ayush prashar

Reputation: 466

How to convert a Flux<List<T>> to a merged Flux<T>?

While working with Project Reactor, there came a use case where I'd want to convert a Flux <List<String>> to a <Flux<String>> where all those lists are flattened to form a Flux. Is there any out of the box method for the same?

Upvotes: 3

Views: 1395

Answers (1)

Vova Bilyachat
Vova Bilyachat

Reputation: 19514

Use .flatMap(Flux::fromIterable)

List<String> list = new ArrayList<>();
var flux = Flux.just(list)
            .flatMap(Flux::fromIterable);

Upvotes: 2

Related Questions