mdedetrich commented on PR #2429:
URL: https://github.com/apache/pekko/pull/2429#issuecomment-3489979836
> 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, `Source.apply` with varargs works fine for the intended purpose
i.e.
```scala
/**
* 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 `Source(1,2,3)`. The issue as @He-Pin
pointed out is when you do weird things like `Source(Array(1, 2, 3),
Array(4,5,6))`. In this case you would get 2 elements in the stream with both
being `Array`'s which can be seen as weird behavior.
In my personal view I don't see this as an issue considering that Source's
sending raw `Array`'s as elements is almost never what people want however it
is still an inconsistency.
On a broader point, for this very reason is why a lot of Scala libraries
have avoided using varargs in constructors entirely
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]