peekLastOrThrow

fun peekLastOrThrow(fn: () -> Throwable): T

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.peekLastOrThrow { IllegalStateException() } == 1)

deque.clear()

deque.peekLastOrThrow { IllegalStateException() } // Exception!

Return

The last item in this deque if this deque is non-empty.

Parameters

fn

Function that will be used to retrieve the exception to throw when this deque is empty.

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

Throws

If this deque is empty.