commonMain.io.github.lyxnx.util.Collections.kt Maven / Gradle / Ivy
package io.github.lyxnx.util
import kotlin.jvm.JvmSynthetic
// ArrayDeque is a kotlin specific collection, so doesn't place nicely with Java
/**
* Pushes an element into this deque as if it were a stack
*/
@JvmSynthetic
public fun ArrayDeque.push(element: T) {
addLast(element)
}
/**
* Pops an element from this deque as if it were a stack
*
* @throws NoSuchElementException if the deque is empty
*/
@JvmSynthetic
public fun ArrayDeque.pop(): T = removeLast()
/**
* Pops an element from this deque as if it were a stack or returns null if the deque is empty
*/
@JvmSynthetic
public fun ArrayDeque.popOrNull(): T? = removeLastOrNull()
/**
* Creates an [ArrayDeque] with the given [elements]
*/
@JvmSynthetic
public fun arrayDequeOf(vararg elements: T): ArrayDeque = ArrayDeque(elements.toList())