push_front: Push an Element to the Front

View source: R/30-api-flexseq-ends.R

push_frontR Documentation

Push an Element to the Front

Description

Returns a new sequence with value prepended at the left end.

Usage

push_front(x, value)

Arguments

x

A flexseq.

value

Element to prepend.

Details

This operation is persistent: x is not modified.

Elements can be named, but only if all are uniquely named (no missing names).

Value

Updated flexseq.

Examples

s <- as_flexseq(letters[2:4])
s2 <- push_front(s, "a")
s2
s  # unchanged

n <- as_flexseq(list(two = 2, three = 3))
new_el <- 1
names(new_el) <- "one"
push_front(n, new_el)

# Named/unnamed mixes are rejected
try(push_front(n, 0))

Immutables documentation built on April 29, 2026, 1:06 a.m.