Skip to content

Instantly share code, notes, and snippets.

@oxbowlakes
Created March 2, 2012 12:08
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save oxbowlakes/1958039 to your computer and use it in GitHub Desktop.
Save oxbowlakes/1958039 to your computer and use it in GitHub Desktop.
Scala interview questions hard
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