View source: R/20-api-generics.R
| split_by_predicate | R Documentation |
Splits at the first point where predicate becomes TRUE while scanning
the sequence.
split_by_predicate(x, predicate, monoid_name)
x |
A |
predicate |
Function applied to accumulated monoid values. |
monoid_name |
Name of the monoid used for scanning. |
This is the two-way variant of split_around_by_predicate().
As with split_around_by_predicate(), a common setup is a custom monoid
created with measure_monoid() and attached via add_monoids().
left and right preserve subclass when the input is a subclass of
flexseq.
A list with fields:
left: elements before the split point.
right: elements from the split point onward.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.