Last active
October 1, 2015 08:48
-
-
Save oxbowlakes/1958028 to your computer and use it in GitHub Desktop.
Scala interview questions
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
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") | |
def ap[B](fab: GOption[A => B]): GOption[B] = sys.error("Implement me (in 15 chars)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks, this has been great fun