Skip to content

Instantly share code, notes, and snippets.

@RyanSusana
Created May 30, 2020 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanSusana/99769e4f67d2de0ad0adee24d5e4f192 to your computer and use it in GitHub Desktop.
Save RyanSusana/99769e4f67d2de0ad0adee24d5e4f192 to your computer and use it in GitHub Desktop.
trait List[T] {
def isEmpty:Boolean
def head: T
def tail: List[T]
}
class Cons[T] (val head: T, val tail: List[T]) extends List[T] {
def isEmpty = false;
}
class Nil[T] extends List[T] {
def isEmpty = true
def head = throw new NoSuchElementException("Empty")
def tail = throw new NoSuchElementException("Empty")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment