Skip to contents

Try to access first or last element and return some default value if not found. In contrast to [at2()], this function provides a less stricter element access, that is, it remains valid even if peeked elements don't exist.

Usage

peekleft(x, default = NULL)

peek(x, default = NULL)

# S3 method for class 'Deque'
peek(x, default = NULL)

# S3 method for class 'Deque'
peekleft(x, default = NULL)

Arguments

x

a Deque object.

default

value to be returned if peeked value does not exist.

Value

The first (peekleft) or last (peek) element.

Details

peek peek at last element of a Deque.

peekleft peek at first element of a Deque.

See also

at2() for strict element extraction

Examples

# Deque
d = deque(1, 2, 3)
peek(d)
#> [1] 3
peekleft(d)
#> [1] 1
peek(deque())
#> NULL
peek(deque(), default = 0)
#> [1] 0
peekleft(deque(), default = 0)
#> [1] 0