Last active
March 24, 2021 17:36
-
-
Save sonumehrotra/78babdef952651c942ac5e6c10faf45c 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
sealed trait MyList[+T] { | |
def isEmpty: Boolean | |
def prepend[R >: T](element: R): MyList[R] = Cons(element, this) | |
} | |
case class Cons[+T](head: T, tail: MyList[T]) extends MyList[T] { | |
override def isEmpty: Boolean = false | |
} | |
case object EmptyList extends MyList[Nothing] { | |
override def isEmpty: Boolean = true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment