https://kotlinlang.org logo
#announcements
Title
# announcements
d

dewildte

10/05/2019, 2:14 PM
Is there any reason Kotlin does not have a native Stack Data Structure?
s

Shawn

10/05/2019, 2:43 PM
Copy code
fun <E> MutableList<E>.push(element: E) = add(element)
fun <E> MutableList<E>.pop(element: E) = removeAt(lastIndex)
1
a stack by any other name
d

dewildte

10/05/2019, 3:52 PM
Yeah I guess I can add the peek function too.
t

trevjones

10/05/2019, 7:29 PM
well done. I ended up making my own set of interfaces to avoid the “3,293,484” functions exposed on the java stack classes
m

Matteo Mirk

10/07/2019, 10:02 AM
Also, you could complement @Shawn nice code with a typealias to have your
Stack
3 Views