pop_at: Pop an Element by Position

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

pop_atR Documentation

Pop an Element by Position

Description

Returns the selected element and the remaining sequence.

Usage

pop_at(x, index)

Arguments

x

A flexseq.

index

One-based position to remove.

Details

This operation is persistent: x is not modified.

Positive integer indices beyond length(x) return a non-throwing miss object with value = NULL and remaining = x. Invalid indices (NA, non-integer, ⁠<= 0⁠, or length not equal to 1) error.

Value

A list with fields:

  • value: the element at index, or NULL when index is out of bounds.

  • remaining: the sequence after removing the selected element.

Examples

x <- flexseq("a", "b", "c", "d")
out <- pop_at(x, 3)
out$value
out$remaining
x  # unchanged

pop_at(x, 10)
try(pop_at(x, 0))

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