popLastOrGet

fun popLastOrGet(fn: () -> Short): Short

Removes and returns the last item in this deque or returns the value returned by fn if this deque is empty.

Example

val deque = dequeOf(1)

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

Return

Either the value that was previously the last item in this deque, if this deque was non-empty, or the value returned by fn if this deque was 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.