Skip to content

Commit 4541f17

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

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

stream-tests/src/test/scala/org/apache/pekko/stream/impl/TraversalBuilderSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ class TraversalBuilderSpec extends PekkoSpec {
521521
}
522522

523523
"find Source.iterable via TraversalBuilder with getValuePresentedSource" in {
524-
val iterable = List("a")
524+
val iterable = List("a", "b", "c")
525525
TraversalBuilder.getValuePresentedSource(Source(iterable)).get.asInstanceOf[IterableSource[
526526
String]].elements should ===(
527527
iterable)

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)