peekEachIndexed

fun peekEachIndexed(reverse: Boolean, fn: (index: Int, value: T) -> Unit)

Calls the given function with each item in this deque and its index.

Example 1

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

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

require(deque.size == 3)

Example 2

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

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

require(deque.size == 3)

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 in this deque.