Skip to content

Instantly share code, notes, and snippets.

@stew
Last active August 29, 2015 14:07
Show Gist options
  • Save stew/ec7056300683446d58a8 to your computer and use it in GitHub Desktop.
Save stew/ec7056300683446d58a8 to your computer and use it in GitHub Desktop.
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