This is an automated email from the ASF dual-hosted git repository. hepin pushed a commit to branch singleSeq in repository https://gitbox.apache.org/repos/asf/pekko.git
commit d5c5032f6fc005f2b53bd02c228d0b714cbd4a33 Author: He-Pin <[email protected]> AuthorDate: Mon Dec 8 11:28:03 2025 +0800 chore: Matching on seq --- .../scala/org/apache/pekko/stream/scaladsl/Source.scala | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Source.scala b/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Source.scala index c08b7de18a..9c1ddd8359 100644 --- a/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Source.scala +++ b/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Source.scala @@ -402,13 +402,15 @@ object Source { * stream will see an individual flow of elements (always starting from the * beginning) regardless of when they subscribed. */ - def apply[T](iterable: immutable.Iterable[T]): Source[T, NotUsed] = { - (iterable.knownSize: @switch) match { - case 0 => empty - case 1 => single(iterable.head) - case _ => - fromGraph(new IterableSource[T](iterable)).withAttributes(DefaultAttributes.iterableSource) - } + def apply[T](iterable: immutable.Iterable[T]): Source[T, NotUsed] = iterable match { + case immutable.Seq() => empty[T] + case immutable.Seq(elem: T @unchecked) => single(elem) + case other => (other.knownSize: @switch) match { + case 0 => empty + case 1 => single(iterable.head) + case _ => + fromGraph(new IterableSource[T](iterable)).withAttributes(DefaultAttributes.iterableSource) + } } /** --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
