Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fromSeq stack-safe #317

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ object AsyncStream {
def fromSeq[A](seq: Seq[A]): AsyncStream[A] = seq match {
case Nil => empty
case _ if SeqUtil.hasKnownSize(seq) && seq.tail.isEmpty => of(seq.head)
case _ => seq.head +:: fromSeq(seq.tail)
case _ => of(seq.head).flatMap(_ +:: fromSeq(seq.tail))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,20 @@ class AsyncStreamTest extends AnyFunSuite with ScalaCheckDrivenPropertyChecks {

assert(Await.result(stream.toSeq()) == Seq(n))
}

test(s"$impl: fromSeq is stack-safe") {
val n = 100000
val longSeq = (0 until n).toSeq
val stream = AsyncStream.fromSeq(longSeq)
.filter(_ > 10)
.filter(_ > 100)
.filter(_ > 1000)
.filter(_ > 10000)
.filter(_ > 100000)
.take(Int.MaxValue)

assert(Await.result(stream.toSeq.liftToTry).isReturn)
}
}

}
Expand Down Expand Up @@ -805,4 +819,4 @@ private object AsyncStreamTest {
}

def seqImpl: Seq[FromSeq] = Seq(Cons, EmbeddedCons, OfFuture, EmbeddedFuture)
}
}