Adindu Stevens
Adindu Stevens

Reputation: 3567

Convert Mono<Stream<String>> to Flux<String>

I have a Mono like this Mono<Stream<String>> and I want to convert it to a Flux like this Flux<String>.
In my junior mind I think it should be simple because Mono<Stream<String>> is the "hope" for a String and Flux<String> is also the "hope" of a String, therefore there should be a simple operator to do the conversion.
I am new to Spring boot webflux, so if there is an operator for this query just show me or tell me why such operation is not possible.

Mono<Stream<String>> authoritiesStream = Mono.just(Stream.of(""));
        
Flux<String> authorities = authoritiesStream.???

I don't want to collect() the stream and use flatMapIterable() to do the conversion because collecting would imply that I have lost my asynch edge. Please teach me
Thank you in advance.

Upvotes: 1

Views: 871

Answers (1)

Alex
Alex

Reputation: 5924

Not sure what is the idea behind Mono<Stream<String>> but assuming you are getting it from another method you could do something like

Flux<String> authorities = authoritiesStream
    .flatMapMany(stream -> Flux.fromStream(stream));

Upvotes: 4

Related Questions