popEachIndexed

fun popEachIndexed(reverse: Boolean = false, fn: (index: Int, value: ULong) -> Unit)

Removes each item off of this deque one at a time and calls the given function with each removed item along with the index of that item in the deque.

Example 1

val deque = dequeOf('a', 'b', 'c')

// Prints:
// 1 -> a
// 2 -> b
// 3 -> c
deque.popEachIndexed { i, it -> println("$i -> $it") }

require(deque.size == 0)

Example 2

val deque = dequeOf('a', 'b', 'c')

// Prints:
// 3 -> 'c'
// 2 -> 'b'
// 1 -> 'a'
deque.popEachIndexed(true) { i, it -> println("$i -> $it") }

require(deque.size == 0)

Parameters

reverse

Whether the iteration should happen in reverse from the back of the deque or forwards from the front of the deque.

fn

Function to call with each item removed from this deque.