Skip to content

Instantly share code, notes, and snippets.

@willf
Forked from casualjim/scala-interview1.scala
Created May 1, 2013 20:48
Show Gist options
  • Save willf/5498263 to your computer and use it in GitHub Desktop.
Save willf/5498263 to your computer and use it in GitHub Desktop.
object GOption {
def some[A](a: A): GOption[A] = new GOption[A] {
def cata[B](n: => B, s: A => B): B = sys.error("Implement me")
}
def none[A]: GOption[A] = new GOption[A] {
def cata[B](n: => B, s: A => B): B = sys.error("Implement me")
}
}
trait GOption[+A] {
import GOption._
def cata[B](none: => B, some: A => B): B
def map[B](f: A => B): GOption[B] = sys.error("Implement me in terms of cata")
def flatMap[B](f: A => GOption[B]): GOption[B] = sys.error("Implement me in terms of cata")
def getOrElse[B >: A](b: => B): B = sys.error("Implement me in terms of cata")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment