% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/20-api-generics.R
\name{split_around_by_predicate}
\alias{split_around_by_predicate}
\title{Split Around First Predicate Match}
\usage{
split_around_by_predicate(t, predicate, monoid_name, accumulator = NULL)
}
\arguments{
\item{t}{A \code{flexseq} (or subclass).}

\item{predicate}{Function applied to accumulated monoid values.}

\item{monoid_name}{Name of the monoid used for scanning.}

\item{accumulator}{Optional starting accumulator value.}
}
\value{
A list with fields:
\itemize{
\item \code{left}: elements before the split point.
\item \code{value}: the matched element at the split point.
\item \code{right}: elements after the split point.
}
}
\description{
Splits at the first point where a \code{predicate} function becomes \code{TRUE}
while scanning the sequence.
}
\details{
This function generally requires the sequence be annotated with
a \code{measure_monoid()}; see the examples and \code{measure_monoid()}
for more information.

\code{value} is the matched leaf entry for the input structure:
\itemize{
\item \code{flexseq}: stored user element.
\item \code{ordered_sequence}: \code{list(value, key)}.
\item \code{priority_queue}: \code{list(value, priority)}.
\item \code{interval_index}: \code{list(value, start, end)}.
}

\code{left} and \code{right} preserve subclass when the input is a subclass of
\code{flexseq}.
}
\examples{
x <- flexseq("a", "b", "c", "d")

# Each element e has measure 1; the accumulated measure for
# a set of elements is computed by the associative function `+`
# along with the identity value 0.
size_monoid <- measure_monoid(`+`, 0L, function(e) 1L)
x2 <- add_monoids(x, list(size = size_monoid))

# the first time the measure stored in the size monoid
# accumulates to greater than or equal to 3 is the 3rd
# element in sequence.
split_around_by_predicate(x2, function(v) v >= 3L, "size")

# Split at the first element
split_around_by_predicate(x2, function(v) v >= 1L, "size")

# Split at the last element
split_around_by_predicate(x2, function(v) v >= 4L, "size")
}
