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

Feature request: Add Source.multi method #1238

Open
He-Pin opened this issue Mar 28, 2024 · 7 comments
Open

Feature request: Add Source.multi method #1238

He-Pin opened this issue Mar 28, 2024 · 7 comments
Labels
t:stream Pekko Streams

Comments

@He-Pin
Copy link
Member

He-Pin commented Mar 28, 2024

Motivation:

There are many Source.from(Arrays.asList(...)) in Java, I think we can add something like Source.multi(...) which work as the Flux.Just(T ...t).

Result:
Replace Source.from(Arrays.asList(1,2,3)) to Source.multi(1,2,3))

@He-Pin He-Pin added the t:stream Pekko Streams label Mar 28, 2024
@Roiocam
Copy link
Member

Roiocam commented Mar 29, 2024

I would prefer overloading Source.from(T...), or like Java Stream API has Source.of(T) and Source.of(T...)?

@He-Pin
Copy link
Member Author

He-Pin commented Mar 29, 2024

I'm not sure about this, Source.from(T ...t) may cause user to wonder does the stream emits T1, T2, T3 ... or just a [T1, T2,T3 ...] array element. I think that's why there is a Source.single for explicit.

So:

  • Source.single for a single element.
  • Source.multi for many elements

Which is a little verbos but very clear

@Roiocam
Copy link
Member

Roiocam commented Mar 29, 2024

Fair to me. It will be easier to use on Java.

@laglangyue
Copy link
Contributor

I vote +1 to Source.of, I like to use Source.of(1) and Source.of(1, 2, 3)
Source.multi(1) equals Source.single(1) , so Source.multi(1) just emit one, it conveyed an erroneous semantics

@He-Pin
Copy link
Member Author

He-Pin commented Mar 29, 2024

How about Source.elements(T ...t) ? of will cause real trouble at Work when you need to cooperate with your work-mate, trust me.

@laglangyue
Copy link
Contributor

How about Source.elements(T ...t) ? of will cause real trouble at Work when you need to cooperate with your work-mate, trust me.

okey

@He-Pin
Copy link
Member Author

He-Pin commented Apr 5, 2024

I just checked https://github.com/smallrye/smallrye-mutiny, which is using items(...)

Multi.createFrom().items(1, 2, 3, 4, 5)
        .onItem().transform(i -> i * 2)
        .select().first(3)
        .onFailure().recoverWithItem(0)
        .subscribe().with(System.out::println);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t:stream Pekko Streams
Projects
None yet
Development

No branches or pull requests

3 participants