fapply: Fapply with S3 dispatch

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

fapplyR Documentation

Fapply with S3 dispatch

Description

fapply() is an S3 generic for applying functions over immutable structures with type-specific dispatch.

Usage

fapply(X, FUN, ...)

Arguments

X

Object to apply over.

FUN

Function to apply.

...

Method-specific arguments.

Details

fapply() returns a new object and preserves class semantics.

Method signatures:

  • fapply.flexseq(X, FUN, ..., preserve_custom_monoids = TRUE)

  • fapply.priority_queue(X, FUN, ..., preserve_custom_monoids = TRUE)

  • fapply.ordered_sequence(X, FUN, ..., preserve_custom_monoids = TRUE)

  • fapply.interval_index(X, FUN, ..., preserve_custom_monoids = TRUE)

For priority_queue, ordered_sequence, and interval_index, FUN receives structured fields (value plus metadata) and should return the new payload value only; ordering metadata is preserved. The name argument is optional: callbacks that only take value/metadata also work.

If supported by the method, preserve_custom_monoids = TRUE keeps added user monoids; FALSE rebuilds with required structural monoids only.

Value

Method-dependent result.

See Also

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

Examples

x <- flexseq("a", "b", "c")
fapply(x, toupper)

q <- priority_queue(one = "a", two = "b", priorities = c(2, 1))
fapply(q, function(value, priority, name) paste0(value, priority))

o <- ordered_sequence(one = "a", two = "b", keys = c(2, 1))
fapply(o, function(value, key, name) paste0(value, "_", key))

ix <- interval_index(one = "a", two = "b", start = c(1, 3), end = c(2, 4))
fapply(ix, function(value, start, end, name) paste0(value, "[", start, ",", end, "]"))

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