Created
November 19, 2020 17:36
-
-
Save ChristopherDavenport/0a91881f6b771dde5f24774ff29ec40d to your computer and use it in GitHub Desktop.
Check Chunk for Streaming Responses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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