Skip to content

Instantly share code, notes, and snippets.

@windymelt
Last active August 29, 2015 13:56
Show Gist options
  • Save windymelt/8886250 to your computer and use it in GitHub Desktop.
Save windymelt/8886250 to your computer and use it in GitHub Desktop.
object StreamT extends StreamTInstances {
// 略
def unfoldM[M[_],A,B](start: B)(f: B => M[Option[(A,B)]])(implicit M: Functor[M]): StreamT[M,A] =
StreamT[M,A](M.map(f(start)) {
case Some((a, b)) => Yield(a, unfoldM(b)(f))
case None => Done
})
def unfold[A,B](b: B)(f: B => Option[(A,B)]): StreamT[Id,A] = unfoldM[Id,A,B](b)(f)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment