% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/20-api-generics.R
\name{split_by_predicate}
\alias{split_by_predicate}
\title{Split into Left and Right Parts}
\usage{
split_by_predicate(x, predicate, monoid_name)
}
\arguments{
\item{x}{A \code{flexseq} (or subclass).}

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

\item{monoid_name}{Name of the monoid used for scanning.}
}
\value{
A list with fields:
\itemize{
\item \code{left}: elements before the split point.
\item \code{right}: elements from the split point onward.
}
}
\description{
Splits at the first point where \code{predicate} becomes \code{TRUE} while scanning
the sequence.
}
\details{
This is the two-way variant of \code{\link[=split_around_by_predicate]{split_around_by_predicate()}}.

As with \code{\link[=split_around_by_predicate]{split_around_by_predicate()}}, a common setup is a custom monoid
created with \code{\link[=measure_monoid]{measure_monoid()}} and attached via \code{\link[=add_monoids]{add_monoids()}}.

\code{left} and \code{right} preserve subclass when the input is a subclass of
\code{flexseq}.
}
\examples{
x <- flexseq("a", "b", "c", "d")
size_monoid <- measure_monoid(`+`, 0L, function(e) 1L)
x2 <- add_monoids(x, list(size = size_monoid))
split_by_predicate(x2, function(v) v >= 3L, "size")

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