% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/20-api-generics.R
\name{fapply}
\alias{fapply}
\title{Fapply with S3 dispatch}
\usage{
fapply(X, FUN, ...)
}
\arguments{
\item{X}{Object to apply over.}

\item{FUN}{Function to apply.}

\item{...}{Method-specific arguments.}
}
\value{
Method-dependent result.
}
\description{
\code{fapply()} is an S3 generic for applying functions over immutable
structures with type-specific dispatch.
}
\details{
\code{fapply()} returns a new object and preserves class semantics.

Method signatures:
\itemize{
\item \code{fapply.flexseq(X, FUN, ..., preserve_custom_monoids = TRUE)}
\item \code{fapply.priority_queue(X, FUN, ..., preserve_custom_monoids = TRUE)}
\item \code{fapply.ordered_sequence(X, FUN, ..., preserve_custom_monoids = TRUE)}
\item \code{fapply.interval_index(X, FUN, ..., preserve_custom_monoids = TRUE)}
}

For \code{priority_queue}, \code{ordered_sequence}, and \code{interval_index},
\code{FUN} receives structured fields (\code{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, \code{preserve_custom_monoids = TRUE} keeps added user
monoids; \code{FALSE} rebuilds with required structural monoids only.
}
\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, "]"))
}
\seealso{
\code{\link[=flexseq]{flexseq()}}, \code{\link[=priority_queue]{priority_queue()}}, \code{\link[=ordered_sequence]{ordered_sequence()}}, \code{\link[=interval_index]{interval_index()}}
}
