Created
December 1, 2016 22:22
-
-
Save edmundnoble/b9e4f9693a8f8601d2d3af7aaba9d5fb 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
@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