pjfanning commented on code in PR #2561:
URL: https://github.com/apache/pekko/pull/2561#discussion_r2599184733
##########
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
{
Review Comment:
Can you add a comment saying that if the Iterable has unknown size, that
knownSize returns -1?
--
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]