popEach

fun popEach(reverse: Boolean = false, fn: (value: Int) -> Unit)

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

Example 1

val deque = dequeOf(1, 2, 3)

// Prints:
// 1
// 2
// 3
deque.popEach { println(it) }

require(deque.size == 0)

Example 2

val deque = dequeOf(1, 2, 3)

// Prints:
// 3
// 2
// 1
deque.popEach(true) { println(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.