as_flexseq: Coerce Objects to 'flexseq'

View source: R/20-api-generics.R

as_flexseqR Documentation

Coerce Objects to flexseq

Description

as_flexseq() is the canonical way to obtain a plain flexseq for full sequence-style operations.

Usage

as_flexseq(x)

Arguments

x

Input object.

Details

For base vectors/lists, this builds a new flexseq preserving element order and names.

For specialized immutable subclasses (priority_queue, ordered_sequence, interval_index), this intentionally drops subclass semantics and returns a plain flexseq.

This is an S3 generic. Notable method behavior:

  • as_flexseq.flexseq(x) returns x unchanged.

  • as_flexseq.priority_queue(x) returns payload items.

  • as_flexseq.ordered_sequence(x) returns payload items.

  • as_flexseq.interval_index(x) returns payload items.

For advanced types, custom monoids are dropped and the rebuilt flexseq keeps only structural monoids (.size, .named_count). For priority_queue, a flexseq of full entry records can be obtained by composing with as.list(): as_flexseq(as.list(x)). For ordered_sequence and interval_index, as.list() also returns payload-only lists, so no direct record-preserving cast is provided.

Value

A plain flexseq.

See Also

flexseq(), priority_queue(), ordered_sequence(), interval_index()

Examples

x <- as_flexseq(1:3)
x

q <- priority_queue("a", "b", priorities = c(2, 1))
as_flexseq(q)

o <- ordered_sequence("a", "b", keys = c(2, 1))
as_flexseq(o)

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