Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mbektimirov/2660525 to your computer and use it in GitHub Desktop.
Save mbektimirov/2660525 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