Transform Flux to Mono, execute method on Mono and transform back to Flux

Viewed 2846

I need to implement this function:

// TODO Capitalize the users username, firstName and lastName 
// using #asyncCapitalizeUser method below

Flux<User> asyncCapitalizeMany(Flux<User> flux) {

}

Mono<User> asyncCapitalizeUser(User u) {
    return Mono.just(
            new User(u.getUsername().toUpperCase(),
                    u.getFirstname().toUpperCase(),
                    u.getLastname().toUpperCase()));
}

My implementation:

return flux
    .map(user -> asyncCapitalizeUser(user))
    .flatMap(Mono::flux)  

Is this correct, and can it be improved?

1 Answers
Related