Skip to content

Instantly share code, notes, and snippets.

@kareblak
Created September 21, 2017 07:33
Show Gist options
  • Save kareblak/6a0dc9f9c044b04d9bc082c37143831d to your computer and use it in GitHub Desktop.
Save kareblak/6a0dc9f9c044b04d9bc082c37143831d to your computer and use it in GitHub Desktop.
def lastB[A, B](implicit S:Strategy): Pipe2[Task, A, B, (A, B)] = (as, bs) =>
bs.uncons1.flatMap {
case None => Stream.empty
case Some((init, newBs)) =>
as.either(newBs).mapAccumulate(init) {
case (b, Left(a)) => (b, Some(a))
case (_, Right(b)) => (b, None)
}.collect { case (b, Some(a)) => (a, b) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment