Enable passing arguments to custom functions

This commit is contained in:
2020-03-11 22:16:29 +01:00
parent 7d61756273
commit 53bba579c1
11 changed files with 110 additions and 32 deletions

View File

@@ -0,0 +1,25 @@
package io.smnp.collection
class Stack<T> private constructor(private val list: MutableList<T>) : List<T> 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 <T> of(vararg items: T): Stack<T> {
return Stack(mutableListOf(*items))
}
}
}