How to flatten Flux<List<T>> to Flux<T>?

Viewed 2279

Hi my code looks like this:

fun mapBatch(batch: List<String>): Mono<List<MyClass>> ...

fun myFun(stream: Flux<String>): Flux<MyClass> {
    return stream
            .bufferTimeout(50, Duration.ofSeconds(60L))
            .flatMap{ batch -> mapBatch(batch) }
            /// now here I would like to get Flux<MyClass> but have Flux<List<MyClass>> 
}

How to get the Flux<T> from Flux<List<T>> ?

1 Answers

You should use .concatMapIterable or .flatMapIterable.

Flux#flatMapIterable is a special operator to "flatten" the item represented as Iterable into a reactive stream of T.

Related