Created
March 2, 2012 12:08
-
-
Save oxbowlakes/1958039 to your computer and use it in GitHub Desktop.
Scala interview questions hard
This file contains hidden or 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
trait MyList[+A] { | |
def fold[B](k: Option[(A, B)] => B): B | |
def map[B](f: A => B): MyList[B] = sys.error("Implement me in terms of fold") | |
def flatMap[B](f: A => MyList[B]): MyList[B] = sys.error("Implement me in terms of fold") | |
def headOption: Option[B] = sys.error("Implement me in terms of fold") | |
def tailOption: Option[MyList[B]] = sys.error("Implement me in terms of fold") | |
def isEmpty = sys.error("Implement me in terms of fold") | |
def length = sys.error("Implement me in terms of fold") | |
} | |
object MyList { | |
def nil[A] = new MyList[A] { | |
def fold[B](k: Option[(A, B)] => B): B = sys.error("Implement me") | |
} | |
def cons[A](h: A, t: MyList[A]) = new MyList[A] { | |
def fold[B](k: Option[(A, B)] => B): B = sys.error("Implement me") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment