kotlin.concurrent.FunctionalQueue.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-stdlib Show documentation
Show all versions of kotlin-stdlib Show documentation
Kotlin Standard Library for JVM
package kotlin.concurrent
import java.util.concurrent.Executor
class FunctionalQueue (
val input: FunctionalList = FunctionalList.emptyList(),
val output: FunctionalList = FunctionalList.emptyList()) {
val size : Int
get() = input.size + output.size
val empty : Boolean
get() = size == 0
public fun add(element: T) : FunctionalQueue = FunctionalQueue(input add element, output)
public fun addFirst(element: T) : FunctionalQueue = FunctionalQueue(input, output add element)
public fun removeFirst() : Pair> =
if(output.empty) {
if(input.empty)
throw java.util.NoSuchElementException()
else
FunctionalQueue(FunctionalList.emptyList(), input.reversed()).removeFirst()
}
else {
Pair(output.head, FunctionalQueue(input, output.tail))
}
}