Skip to content

Instantly share code, notes, and snippets.

@rrmckinley
Created December 10, 2013 18:44
Show Gist options
  • Save rrmckinley/7895816 to your computer and use it in GitHub Desktop.
Save rrmckinley/7895816 to your computer and use it in GitHub Desktop.
def yipWhenL[I, O, O2](ord: (I, O) => Ordering)(f: (I, Option[O]) => O2): Wye[I, O, O2] = {
val fbL: Tee[I, O, O2] = tee.passL[I] map (f(_, None))
def go(io: Option[I], oo: Option[O]): Wye[I, O, O2] = {
io match {
case None => awaitL[I].flatMap { i => go(Some(i), oo) }
case Some(i) => oo match {
case None => awaitR[O]
.flatMap { o => go(io, Some(o)) }
.orElse { emit(f(i, None)) fby go(None, None) }
case Some(o) => ord(i, o) match {
case Ordering.LT => emit(f(i, None)) fby go(None, oo)
case Ordering.EQ => emit(f(i, oo)) fby go(None, None)
case Ordering.GT => go(io, None)
}
}
}
}
go(None, None)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment