Created
May 30, 2020 19:50
-
-
Save RyanSusana/99769e4f67d2de0ad0adee24d5e4f192 to your computer and use it in GitHub Desktop.
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
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