sub-.ordered_sequence: Indexing for Ordered Sequences

sub-.ordered_sequenceR Documentation

Indexing for Ordered Sequences

Description

Read indexing treats vectors as selectors and returns subsets in key order. Out-of-order selectors are canonicalized with a warning. Replacement indexing is blocked to prevent order-breaking writes.

Usage

## S3 method for class 'ordered_sequence'
x[i, ...]

## S3 method for class 'ordered_sequence'
x[[i, ...]]

## S3 replacement method for class 'ordered_sequence'
x[i] <- value

## S3 replacement method for class 'ordered_sequence'
x[[i]] <- value

## S3 method for class 'ordered_sequence'
x$name

## S3 replacement method for class 'ordered_sequence'
x$name <- value

Arguments

x

An ordered_sequence.

i

Index input.

...

Unused.

value

Replacement value (unsupported).

name

Element name (for $ and ⁠$<-⁠).

Details

Vector selectors are treated as membership selectors, not output-order instructions.

  • Integer/character vectors are normalized to unique positions and returned in canonical sequence order.

  • Out-of-order selector vectors trigger a warning and are canonicalized.

  • Duplicate selectors are rejected.

  • Replacement indexing (⁠[<-⁠, ⁠[[<-⁠, ⁠$<-⁠) is unsupported.

Value

Read methods return ordered payload values/subsets; replacement forms always error.

Examples

x <- ordered_sequence(a = "A", b = "B", c = "C", keys = c(1, 2, 3))

x[c(3, 1)]          # warning; result returned in key order
x[c("c", "a")]      # warning; result returned in key order
x[c(TRUE, FALSE, TRUE)]
x[["b"]]
x$b

try(x[c(2, 2)])
try(x$b <- "updated")

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