Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ChristopherDavenport/0a91881f6b771dde5f24774ff29ec40d to your computer and use it in GitHub Desktop.
Save ChristopherDavenport/0a91881f6b771dde5f24774ff29ec40d to your computer and use it in GitHub Desktop.
Check Chunk for Streaming Responses
import fs2._
object CheckChunk {
def checkChunk[F[_]: Sync, A](s: Stream[F, A]): F[Option[Stream[F, A]]] = {
s.pull
.uncons
.flatMap {
case None => Pull.output1(None)
case Some((c, s)) => Pull.extendScopeTo(Stream.chunk(c) ++ s).flatMap(s => Pull.output1(Some(s)))
}
.stream
.compile
.lastOrError
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment