Is there a good way to conditionally skip or take elements in a Flux?

Viewed 20

May I ask whether it is possible to skip and take the elements in a Flux conditionally?

My code is like this currently:

Flux users = getUsersService.getUsers();
if (userLimit != null) {
return users.skip(CURTAIN_NUMBER).take(userLimit);
}
return users;

And I wonder whether it can be more elegant like this:

return getUsersService.getUsers()
       .if(userLimit != null)
       .skip(CURTAIN_NUMBER).take(userLimit);

It doesn't have to be like what I put above. But could you please help me make my code look cleaner? Thanks a lot. :)

0 Answers
Related