Skip to content

Instantly share code, notes, and snippets.

Created July 11, 2019 20:33
What would you like to do?
sealed class List<out E>
object Empty: List<Nothing>() {
override fun toString()= "[]"
data class Cons<E>(val head: E, val tail: List<E>): List<E>() {
override fun toString(): String = "$head :: $tail"
fun main() {
val myList1 = Empty
val myList2 = Cons(1, myList1)
val myList3 = Cons(2, myList2)
println("myList1: $myList1")
println("myList2: $myList2")
println("myList3: $myList3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment