-
Notifications
You must be signed in to change notification settings - Fork 186
feat: Add Source#items #2429
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
feat: Add Source#items #2429
Conversation
|
Just to add onto what I said, I was apprehensive adding the @raboof Would be good to get your opinion on this as well. |
|
Isn't this the same as #2416? |
Yes it is but for some context, when I reviewed this feature I questioned the premise of However as @He-Pin pointed out, this does create some discrepencies on how sources are created |
|
I'm fairly neutral on this. If the Source.apply can't be implemented to do what we want then Source.elements is fine with me. |
To be clear, /**
* Create a `Source` from the given elements.
*
* @since 1.3.0
*/
@varargs
@SafeVarargs
@SuppressWarnings(Array("varargs"))
def apply[T](elements: T*): javadsl.Source[T, NotUsed] = {
if (elements.isEmpty) {
empty()
} else if (elements.length == 1) {
single(elements.head)
} else {
new Source(scaladsl.Source(elements))
}
}works totally fine, allowing you to do In my personal view I don't see this as an issue considering that Source's sending raw On a broader point, for this very reason is why a lot of Scala libraries have avoided using varargs in constructors entirely. The language is succint/expressive enough that Scala users are fine with |
|
Actually @He-Pin , I think you might be able to solve this issue by adding |
|
I would like to make this just a |
For javadsl |
|
There is a |
|
I don't think a source created with 2 arrays should be automatically flattened but if other source functions automatically flatten inputs then maybe this should too. I would still favour not automatically flattening unless this were a few examples of it already in Pekko. |
|
Yes, the problem of make |
|
@mdedetrich @pjfanning Should I just remove the scaladsl's elements? and just keep the java one? |
|
Woops forgot about this, will post a question in Scala contributors |
|
Created a thread here https://contributors.scala-lang.org/t/idiomatic-approach-to-apply-with-varargs/7285, lets see what Scala community says |
|
@mdedetrich @pjfanning Should we rename |
|
@mdedetrich @pjfanning It's renmaed to items as suggested |
stream/src/main/scala/org/apache/pekko/stream/scaladsl/Source.scala
Outdated
Show resolved
Hide resolved
Added one comment |
|
@mdedetrich Would you like to take a look at this? |
mdedetrich
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
(cherry picked from commit f0db8f0)
(cherry picked from commit f0db8f0)
Motivation:
refs: #2416
It's named just in Flux and ambArray in Flowable.
@mdedetrich want the Scala method to be
Source.apply, and then we can callSource(1,2,3,4), wdyt @pjfanning .if we do that, then
Source(Array(1,2,3)will emit1,2,3, and Source(Array(1,2,3), Array(1,2,3)will emitArray(1,2,3), Array(1,2,3)`