Kirill Sereda
Kirill Sereda

Reputation: 549

Reactor WebFlux: help to understand how to work flatMap()

Please help to understand how can I use fkatMap() in my example:

Flux.just("1,2,3", "4,5,6")
                .flatMap(// to do something)
                .collect(Collectors.toList())
                .subscribe(System.out::println);

I read the documentation. I understood how to work flatMap() but I can't understand how I need to use in my example. Thanks.

Upvotes: 0

Views: 387

Answers (1)

Stepan Tsybulski
Stepan Tsybulski

Reputation: 1181

As Kayaman already answered, you can do the following:

Flux.just("1,2,3", "4,5,6")
        .flatMap(i -> Flux.fromIterable(Arrays.asList(i.split(","))))
        .collect(Collectors.toList())
        .subscribe(System.out::println);

Upvotes: 1

Related Questions