Last active
August 29, 2015 14:07
-
-
Save stew/ec7056300683446d58a8 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
import scalaz._ | |
import Maybe._ | |
case class CofreeNEL[A](cf: Cofree[Maybe, A]) { | |
def +:(a: A): CofreeNEL[A] = CofreeNEL(Cofree(a, just(cf))) | |
def head: A = cf.head | |
def tail: Maybe[CofreeNEL[A]] = cf.tail.map(CofreeNEL.apply) | |
def map[B](f: A=>B): CofreeNEL[B] = CofreeNEL(cf map f) | |
def flatMap[B](f: A => CofreeNEL[B]): CofreeNEL[B] = CofreeNEL(Bind[({type l[A]=Cofree[Maybe, A]})#l].bind(cf)(f andThen (_.cf))) | |
} | |
object CofreeNEL { | |
def point[A](a: => A): CofreeNEL[A] = CofreeNEL(Cofree(a, empty)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment