Skip to content

Commit d5c5032

Browse files
committed
chore: Matching on seq
1 parent a536fe3 commit d5c5032

File tree

1 file changed

+9
-7
lines changed
  • stream/src/main/scala/org/apache/pekko/stream/scaladsl

1 file changed

+9
-7
lines changed

stream/src/main/scala/org/apache/pekko/stream/scaladsl/Source.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,15 @@ object Source {
402402
* stream will see an individual flow of elements (always starting from the
403403
* beginning) regardless of when they subscribed.
404404
*/
405-
def apply[T](iterable: immutable.Iterable[T]): Source[T, NotUsed] = {
406-
(iterable.knownSize: @switch) match {
407-
case 0 => empty
408-
case 1 => single(iterable.head)
409-
case _ =>
410-
fromGraph(new IterableSource[T](iterable)).withAttributes(DefaultAttributes.iterableSource)
411-
}
405+
def apply[T](iterable: immutable.Iterable[T]): Source[T, NotUsed] = iterable match {
406+
case immutable.Seq() => empty[T]
407+
case immutable.Seq(elem: T @unchecked) => single(elem)
408+
case other => (other.knownSize: @switch) match {
409+
case 0 => empty
410+
case 1 => single(iterable.head)
411+
case _ =>
412+
fromGraph(new IterableSource[T](iterable)).withAttributes(DefaultAttributes.iterableSource)
413+
}
412414
}
413415

414416
/**

0 commit comments

Comments
 (0)