package io.smnp.collection class Stack private constructor(private val list: MutableList) : List by list { fun push(item: T) { list.add(item) } fun pop(): T? { if(list.isEmpty()) { return null } val last = list.last() list.removeAt(list.size-1) return last } fun top() = list.last() companion object { fun of(vararg items: T): Stack { return Stack(mutableListOf(*items)) } } }