Skip to content

Instantly share code, notes, and snippets.

@sonumehrotra
Last active March 24, 2021 17:36
Show Gist options
  • Save sonumehrotra/78babdef952651c942ac5e6c10faf45c to your computer and use it in GitHub Desktop.
Save sonumehrotra/78babdef952651c942ac5e6c10faf45c to your computer and use it in GitHub Desktop.
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