peekLastOrGet

fun peekLastOrGet(fn: () -> UShort): UShort

Returns the last item in this deque if it is not empty, otherwise returns the value returned by the given function.

Example

val deque = dequeOf(1)

assert(deque.peekLastOrGet { 6 } == 1)

deque.clear()

assert(deque.peekLastOrGet { 6 } == 6)

Return

Either the last item in this deque if this deque is non-empty, or the value returned by fn if this deque is empty.

Parameters

fn

Function that will be used to retrieve the value to return when this deque is empty.

This function will not be called if this deque is not empty.