Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Flux#justOrEmpty method #4001

Open
He-Pin opened this issue Feb 27, 2025 · 2 comments
Open

Add Flux#justOrEmpty method #4001

He-Pin opened this issue Feb 27, 2025 · 2 comments
Labels
status/need-user-input This needs user input to proceed

Comments

@He-Pin
Copy link
Contributor

He-Pin commented Feb 27, 2025

Motivation:
I have some cases when I'm using Flux.

    if (resp == null) {
        return Flux.empty();
    } else {
        return Flux.just(resp);
    }

There is an Stream#ofNullable, so I think this method would be helpful.

@He-Pin He-Pin added the type/enhancement A general enhancement label Feb 27, 2025
@He-Pin He-Pin changed the title Add Flux#ofNullable method Add Flux#justOrEmpty method Feb 27, 2025
@chemicL
Copy link
Member

chemicL commented Mar 10, 2025

Hey, thanks for the suggestion.

Mono.justOrEmpty(@Nullable T) exists since #26
You can combine it with .flux():

Object x = null;
Flux<Object> f = Mono.justOrEmpty(x).flux();

f.subscribe(System.out::println, System.err::println, () -> System.out.println("done"));

I am not sure that we need the same factory in Flux. What is stopping you from returning Mono directly in the use cases you encounter?

@chemicL chemicL added status/need-user-input This needs user input to proceed and removed type/enhancement A general enhancement labels Mar 10, 2025
@He-Pin
Copy link
Contributor Author

He-Pin commented Mar 12, 2025

That's true, but sometimes, the return type is fixed to Flux , because there may be more elements. We are using this in an SSR scene, it's only one element once it fails, or I can make the return type a Publisher<T>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/need-user-input This needs user input to proceed
Projects
None yet
Development

No branches or pull requests

2 participants