Reputation: 26441
I'm having following Flux
:
val myFlux = Flux.just("a", "b", "duck", "c", "d")
I would like to transform it in a way that each occurrence of duck
will produce two elements (eg. Leg
)
So:
myMyFlux.magicTransformation()
should produce:
"a", "b", "leg", "leg", "c", "d"
Upvotes: 0
Views: 190
Reputation: 780
You can use flatMap
to map duck
into two elements.
val myFlux = Flux.just("a", "b", "duck", "c", "d")
myFlux.flatMap {
if (it == "duck") {
Flux.just("leg", "leg")
} else {
Mono.just(it)
}
}.subscribe(System.out::println)
Upvotes: 1