Created
October 22, 2019 20:00
-
-
Save djspiewak/d0d7a50fa29015c119e66c20b417f4e4 to your computer and use it in GitHub Desktop.
This file contains 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
def both[F[_]: Concurrent, A, B](s1: Stream[F, A], s2: Stream[F, B]): Stream[F, (A, B)] = { | |
def awaitCombine(s: Stream[F, Either[A, B]]): Pull[F, (A, B), Unit] = | |
s.pull.uncons1 flatMap { | |
case Some((Left(a), tail)) => | |
tail.pull.uncons1 flatMap { | |
case Some((Right(b), tail)) => | |
Pull.output1((a, b)) >> awaitCombine(tail) | |
case None => | |
Pull.done | |
} | |
case Some((Right(b), tail)) => | |
tail.pull.uncons1 flatMap { | |
case Some((Left(a), tail)) => | |
Pull.output1((a, b)) >> awaitCombine(tail) | |
case None => | |
Pull.done | |
} | |
case None => | |
Pull.done | |
} | |
awaitCombine(s1.either(s2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment