At feat: Add Source#elements by He-Pin · Pull Request #2429 · apache/pekko · GitHub (pekko-streams) we are discussing adding a varargs constructor to a Source (which is a pure stream), i.e.
def apply[T](elements: T*): Source[T, NotUsed]
With this you can use very concise syntax to create a Source i.e. Source(1,2,3). The issue is that using this syntax has some problems, i.e. if you do something like Source(List(1,2,3),List(4,5,6)) it will just create a Source that emits 2 elements, each one being an List (one containing 1,2,3 and the other 4,5,6) where as doing Source(List(1,2,3)) will construct a Source that just emits 1,2,3 as distinct elements (pekko-streams already has an existing apply for immutable collections)
Essentially this means we are kind of in a battle of consistency in passed arguments (i.e. whatever is passed in must be emitted as the exact same element) versus actually providing a benefit to end users in terms of concise syntax for constructing a Source. For example, originally in that PR the proposal was to have a specific non-apply method for varargs, i.e.
def elements[T](elements: T*): Source[T, NotUsed]
However such a method is kind of pointless given that Source.elements(1,2,3) is even longer than Source(List(1,2,3)) so its not providing much benefit.
So question is, what really is the Scala idiomatic way of handling this issue and how do other libraries/community design with this? I am personally of the view that varargs in general are not even being used that often in Scala and so there is merit in not even bothering to add support for it in our scaladsl (its still being added to our javadsl but thats separate).