Skip to content

Instantly share code, notes, and snippets.

@edmundnoble
Created December 1, 2016 22:22
Show Gist options
  • Save edmundnoble/b9e4f9693a8f8601d2d3af7aaba9d5fb to your computer and use it in GitHub Desktop.
Save edmundnoble/b9e4f9693a8f8601d2d3af7aaba9d5fb to your computer and use it in GitHub Desktop.
@inline final def cataM[F[_] : Traverse, M[_] : Monad, A, B]
(tf: Cofree[F, A])(destroy: (A, F[B]) => M[B]): M[B] = {
val head: A = tf.head
val tail: F[Cofree[F, A]] = tf.tailEval.value
val looped: M[F[B]] = tail.traverse(cataM(_)(destroy))
val destroyed: M[B] = looped.flatMap(destroy(head, _))
destroyed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment